@@ -2279,76 +2279,56 @@ impl<'tcx> TyCtxt<'tcx> {
22792279
22802280 /// Returns `true` if the impls are the same polarity and the trait either
22812281 /// has no items or is annotated `#[marker]` and prevents item overrides.
2282+ #[ instrument( level = "debug" , skip( self ) , ret) ]
22822283 pub fn impls_are_allowed_to_overlap (
22832284 self ,
22842285 def_id1 : DefId ,
22852286 def_id2 : DefId ,
22862287 ) -> Option < ImplOverlapKind > {
2288+ let impl_trait_ref1 = self . impl_trait_ref ( def_id1) ;
2289+ let impl_trait_ref2 = self . impl_trait_ref ( def_id2) ;
22872290 // If either trait impl references an error, they're allowed to overlap,
22882291 // as one of them essentially doesn't exist.
2289- if self . impl_trait_ref ( def_id1) . map_or ( false , |tr| tr. subst_identity ( ) . references_error ( ) )
2290- || self
2291- . impl_trait_ref ( def_id2)
2292- . map_or ( false , |tr| tr. subst_identity ( ) . references_error ( ) )
2292+ if impl_trait_ref1. map_or ( false , |tr| tr. subst_identity ( ) . references_error ( ) )
2293+ || impl_trait_ref2. map_or ( false , |tr| tr. subst_identity ( ) . references_error ( ) )
22932294 {
22942295 return Some ( ImplOverlapKind :: Permitted { marker : false } ) ;
22952296 }
22962297
22972298 match ( self . impl_polarity ( def_id1) , self . impl_polarity ( def_id2) ) {
22982299 ( ImplPolarity :: Reservation , _) | ( _, ImplPolarity :: Reservation ) => {
22992300 // `#[rustc_reservation_impl]` impls don't overlap with anything
2300- debug ! (
2301- "impls_are_allowed_to_overlap({:?}, {:?}) = Some(Permitted) (reservations)" ,
2302- def_id1, def_id2
2303- ) ;
23042301 return Some ( ImplOverlapKind :: Permitted { marker : false } ) ;
23052302 }
23062303 ( ImplPolarity :: Positive , ImplPolarity :: Negative )
23072304 | ( ImplPolarity :: Negative , ImplPolarity :: Positive ) => {
23082305 // `impl AutoTrait for Type` + `impl !AutoTrait for Type`
2309- debug ! (
2310- "impls_are_allowed_to_overlap({:?}, {:?}) - None (differing polarities)" ,
2311- def_id1, def_id2
2312- ) ;
23132306 return None ;
23142307 }
23152308 ( ImplPolarity :: Positive , ImplPolarity :: Positive )
23162309 | ( ImplPolarity :: Negative , ImplPolarity :: Negative ) => { }
23172310 } ;
23182311
23192312 let is_marker_overlap = {
2320- let is_marker_impl = |def_id : DefId | -> bool {
2321- let trait_ref = self . impl_trait_ref ( def_id) ;
2313+ let is_marker_impl = |trait_ref : Option < EarlyBinder < TraitRef < ' _ > > > | -> bool {
23222314 trait_ref. map_or ( false , |tr| self . trait_def ( tr. skip_binder ( ) . def_id ) . is_marker )
23232315 } ;
2324- is_marker_impl ( def_id1 ) && is_marker_impl ( def_id2 )
2316+ is_marker_impl ( impl_trait_ref1 ) && is_marker_impl ( impl_trait_ref2 )
23252317 } ;
23262318
23272319 if is_marker_overlap {
2328- debug ! (
2329- "impls_are_allowed_to_overlap({:?}, {:?}) = Some(Permitted) (marker overlap)" ,
2330- def_id1, def_id2
2331- ) ;
23322320 Some ( ImplOverlapKind :: Permitted { marker : true } )
23332321 } else {
23342322 if let Some ( self_ty1) = self . issue33140_self_ty ( def_id1) {
23352323 if let Some ( self_ty2) = self . issue33140_self_ty ( def_id2) {
23362324 if self_ty1 == self_ty2 {
2337- debug ! (
2338- "impls_are_allowed_to_overlap({:?}, {:?}) - issue #33140 HACK" ,
2339- def_id1, def_id2
2340- ) ;
23412325 return Some ( ImplOverlapKind :: Issue33140 ) ;
23422326 } else {
2343- debug ! (
2344- "impls_are_allowed_to_overlap({:?}, {:?}) - found {:?} != {:?}" ,
2345- def_id1, def_id2, self_ty1, self_ty2
2346- ) ;
2327+ debug ! ( "found {self_ty1:?} != {self_ty2:?}" ) ;
23472328 }
23482329 }
23492330 }
23502331
2351- debug ! ( "impls_are_allowed_to_overlap({:?}, {:?}) = None" , def_id1, def_id2) ;
23522332 None
23532333 }
23542334 }
@@ -2405,7 +2385,8 @@ impl<'tcx> TyCtxt<'tcx> {
24052385 | ty:: InstanceDef :: Virtual ( ..)
24062386 | ty:: InstanceDef :: ClosureOnceShim { .. }
24072387 | ty:: InstanceDef :: DropGlue ( ..)
2408- | ty:: InstanceDef :: CloneShim ( ..) => self . mir_shims ( instance) ,
2388+ | ty:: InstanceDef :: CloneShim ( ..)
2389+ | ty:: InstanceDef :: FnPtrAddrShim ( ..) => self . mir_shims ( instance) ,
24092390 }
24102391 }
24112392
0 commit comments