Skip to content

Commit 0529ccf

Browse files
committed
Fix allow_internal_unstable for (min_)specialization
1 parent 1d8d7b1 commit 0529ccf

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
2626
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
2727
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
2828
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
29-
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
29+
use rustc_span::{sym, ErrorGuaranteed, Span, DUMMY_SP};
3030

3131
use super::util;
3232
use super::SelectionContext;
@@ -144,8 +144,22 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
144144
// taking advantage of upstream ones.
145145
let features = tcx.features();
146146
let specialization_enabled = features.specialization || features.min_specialization;
147-
if !specialization_enabled && (impl1_def_id.is_local() || impl2_def_id.is_local()) {
148-
return false;
147+
if !specialization_enabled && impl1_def_id.is_local() {
148+
let span = tcx.def_span(impl1_def_id);
149+
if !span.allows_unstable(sym::specialization)
150+
&& !span.allows_unstable(sym::min_specialization)
151+
{
152+
return false;
153+
}
154+
}
155+
156+
if !specialization_enabled && impl2_def_id.is_local() {
157+
let span = tcx.def_span(impl2_def_id);
158+
if !span.allows_unstable(sym::specialization)
159+
&& !span.allows_unstable(sym::min_specialization)
160+
{
161+
return false;
162+
}
149163
}
150164

151165
// We determine whether there's a subset relationship by:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
// test for #119950
3+
// compile-flags: --crate-type lib
4+
5+
#![allow(internal_features)]
6+
#![feature(allow_internal_unstable)]
7+
8+
#[allow_internal_unstable(min_specialization)]
9+
macro_rules! test {
10+
() => {
11+
struct T<U>(U);
12+
trait Tr {}
13+
impl<U> Tr for T<U> {}
14+
impl Tr for T<u8> {}
15+
}
16+
}
17+
18+
test! {}

0 commit comments

Comments
 (0)