@@ -142,23 +142,29 @@ pub fn translate_args_with_cause<'tcx>(
142142pub ( super ) fn specializes ( tcx : TyCtxt < ' _ > , ( impl1_def_id, impl2_def_id) : ( DefId , DefId ) ) -> bool {
143143 // The feature gate should prevent introducing new specializations, but not
144144 // taking advantage of upstream ones.
145+ // If specialization is enabled for this crate then no extra checks are needed.
146+ // If it's not, and either of the `impl`s is local to this crate, then this definitely
147+ // isn't specializing - unless specialization is enabled for the `impl` span,
148+ // e.g. if it comes from an `allow_internal_unstable` macro
145149 let features = tcx. features ( ) ;
146150 let specialization_enabled = features. specialization || features. min_specialization ;
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 ;
151+ if !specialization_enabled {
152+ if impl1_def_id. is_local ( ) {
153+ let span = tcx. def_span ( impl1_def_id) ;
154+ if !span. allows_unstable ( sym:: specialization)
155+ && !span. allows_unstable ( sym:: min_specialization)
156+ {
157+ return false ;
158+ }
153159 }
154- }
155160
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 ;
161+ if impl2_def_id. is_local ( ) {
162+ let span = tcx. def_span ( impl2_def_id) ;
163+ if !span. allows_unstable ( sym:: specialization)
164+ && !span. allows_unstable ( sym:: min_specialization)
165+ {
166+ return false ;
167+ }
162168 }
163169 }
164170
0 commit comments