@@ -2279,76 +2279,56 @@ impl<'tcx> TyCtxt<'tcx> {
2279
2279
2280
2280
/// Returns `true` if the impls are the same polarity and the trait either
2281
2281
/// has no items or is annotated `#[marker]` and prevents item overrides.
2282
+ #[ instrument( level = "debug" , skip( self ) , ret) ]
2282
2283
pub fn impls_are_allowed_to_overlap (
2283
2284
self ,
2284
2285
def_id1 : DefId ,
2285
2286
def_id2 : DefId ,
2286
2287
) -> Option < ImplOverlapKind > {
2288
+ let impl_trait_ref1 = self . impl_trait_ref ( def_id1) ;
2289
+ let impl_trait_ref2 = self . impl_trait_ref ( def_id2) ;
2287
2290
// If either trait impl references an error, they're allowed to overlap,
2288
2291
// 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 ( ) )
2293
2294
{
2294
2295
return Some ( ImplOverlapKind :: Permitted { marker : false } ) ;
2295
2296
}
2296
2297
2297
2298
match ( self . impl_polarity ( def_id1) , self . impl_polarity ( def_id2) ) {
2298
2299
( ImplPolarity :: Reservation , _) | ( _, ImplPolarity :: Reservation ) => {
2299
2300
// `#[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
- ) ;
2304
2301
return Some ( ImplOverlapKind :: Permitted { marker : false } ) ;
2305
2302
}
2306
2303
( ImplPolarity :: Positive , ImplPolarity :: Negative )
2307
2304
| ( ImplPolarity :: Negative , ImplPolarity :: Positive ) => {
2308
2305
// `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
- ) ;
2313
2306
return None ;
2314
2307
}
2315
2308
( ImplPolarity :: Positive , ImplPolarity :: Positive )
2316
2309
| ( ImplPolarity :: Negative , ImplPolarity :: Negative ) => { }
2317
2310
} ;
2318
2311
2319
2312
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 {
2322
2314
trait_ref. map_or ( false , |tr| self . trait_def ( tr. skip_binder ( ) . def_id ) . is_marker )
2323
2315
} ;
2324
- is_marker_impl ( def_id1 ) && is_marker_impl ( def_id2 )
2316
+ is_marker_impl ( impl_trait_ref1 ) && is_marker_impl ( impl_trait_ref2 )
2325
2317
} ;
2326
2318
2327
2319
if is_marker_overlap {
2328
- debug ! (
2329
- "impls_are_allowed_to_overlap({:?}, {:?}) = Some(Permitted) (marker overlap)" ,
2330
- def_id1, def_id2
2331
- ) ;
2332
2320
Some ( ImplOverlapKind :: Permitted { marker : true } )
2333
2321
} else {
2334
2322
if let Some ( self_ty1) = self . issue33140_self_ty ( def_id1) {
2335
2323
if let Some ( self_ty2) = self . issue33140_self_ty ( def_id2) {
2336
2324
if self_ty1 == self_ty2 {
2337
- debug ! (
2338
- "impls_are_allowed_to_overlap({:?}, {:?}) - issue #33140 HACK" ,
2339
- def_id1, def_id2
2340
- ) ;
2341
2325
return Some ( ImplOverlapKind :: Issue33140 ) ;
2342
2326
} 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:?}" ) ;
2347
2328
}
2348
2329
}
2349
2330
}
2350
2331
2351
- debug ! ( "impls_are_allowed_to_overlap({:?}, {:?}) = None" , def_id1, def_id2) ;
2352
2332
None
2353
2333
}
2354
2334
}
@@ -2405,7 +2385,8 @@ impl<'tcx> TyCtxt<'tcx> {
2405
2385
| ty:: InstanceDef :: Virtual ( ..)
2406
2386
| ty:: InstanceDef :: ClosureOnceShim { .. }
2407
2387
| ty:: InstanceDef :: DropGlue ( ..)
2408
- | ty:: InstanceDef :: CloneShim ( ..) => self . mir_shims ( instance) ,
2388
+ | ty:: InstanceDef :: CloneShim ( ..)
2389
+ | ty:: InstanceDef :: FnPtrAddrShim ( ..) => self . mir_shims ( instance) ,
2409
2390
}
2410
2391
}
2411
2392
0 commit comments