about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2024-01-14 13:22:43 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2024-01-14 13:50:02 +0000
commit0529ccf341516b098554ccc82a77553159316c2a (patch)
treed6be29adfddfb6e752b742004150a9128b36aedc
parent1d8d7b16cbcd048e98359cd0d42b03bc1710cca8 (diff)
downloadrust-0529ccf341516b098554ccc82a77553159316c2a.tar.gz
rust-0529ccf341516b098554ccc82a77553159316c2a.zip
Fix `allow_internal_unstable` for `(min_)specialization`
-rw-r--r--compiler/rustc_trait_selection/src/traits/specialize/mod.rs20
-rw-r--r--tests/ui/specialization/allow_internal_unstable.rs18
2 files changed, 35 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs
index 200d022c80c..d3862451a01 100644
--- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs
@@ -26,7 +26,7 @@ use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
 use rustc_middle::ty::{GenericArgs, GenericArgsRef};
 use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
 use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
-use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
+use rustc_span::{sym, ErrorGuaranteed, Span, DUMMY_SP};
 
 use super::util;
 use super::SelectionContext;
@@ -144,8 +144,22 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
     // taking advantage of upstream ones.
     let features = tcx.features();
     let specialization_enabled = features.specialization || features.min_specialization;
-    if !specialization_enabled && (impl1_def_id.is_local() || impl2_def_id.is_local()) {
-        return false;
+    if !specialization_enabled && impl1_def_id.is_local() {
+        let span = tcx.def_span(impl1_def_id);
+        if !span.allows_unstable(sym::specialization)
+            && !span.allows_unstable(sym::min_specialization)
+        {
+            return false;
+        }
+    }
+
+    if !specialization_enabled && impl2_def_id.is_local() {
+        let span = tcx.def_span(impl2_def_id);
+        if !span.allows_unstable(sym::specialization)
+            && !span.allows_unstable(sym::min_specialization)
+        {
+            return false;
+        }
     }
 
     // We determine whether there's a subset relationship by:
diff --git a/tests/ui/specialization/allow_internal_unstable.rs b/tests/ui/specialization/allow_internal_unstable.rs
new file mode 100644
index 00000000000..317782b7b72
--- /dev/null
+++ b/tests/ui/specialization/allow_internal_unstable.rs
@@ -0,0 +1,18 @@
+// check-pass
+// test for #119950
+// compile-flags: --crate-type lib
+
+#![allow(internal_features)]
+#![feature(allow_internal_unstable)]
+
+#[allow_internal_unstable(min_specialization)]
+macro_rules! test {
+    () => {
+        struct T<U>(U);
+        trait Tr {}
+        impl<U> Tr for T<U> {}
+        impl Tr for T<u8> {}
+    }
+}
+
+test! {}