about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2024-01-14 13:48:58 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2024-01-14 19:07:13 +0000
commiteb63d3a49d7681d6ede7dc1bcac7bb1125ff7132 (patch)
treef3c4b00d316fecb0e1238ff3530b7fe81359efcd /compiler/rustc_trait_selection/src/traits
parent0529ccf341516b098554ccc82a77553159316c2a (diff)
downloadrust-eb63d3a49d7681d6ede7dc1bcac7bb1125ff7132.tar.gz
rust-eb63d3a49d7681d6ede7dc1bcac7bb1125ff7132.zip
`allow_internal_unstable(min_specialization)` on `newtype_index`
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
-rw-r--r--compiler/rustc_trait_selection/src/traits/specialize/mod.rs32
1 files changed, 19 insertions, 13 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs
index d3862451a01..b37d9714ddd 100644
--- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs
@@ -142,23 +142,29 @@ pub fn translate_args_with_cause<'tcx>(
 pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, DefId)) -> bool {
     // The feature gate should prevent introducing new specializations, but not
     // taking advantage of upstream ones.
+    // If specialization is enabled for this crate then no extra checks are needed.
+    // If it's not, and either of the `impl`s is local to this crate, then this definitely
+    // isn't specializing - unless specialization is enabled for the `impl` span,
+    // e.g. if it comes from an `allow_internal_unstable` macro
     let features = tcx.features();
     let specialization_enabled = features.specialization || features.min_specialization;
-    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 {
+        if 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;
+        if 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;
+            }
         }
     }