@@ -10,8 +10,9 @@ use rustc_hir as hir;
1010use rustc_hir:: LangItem ;
1111use rustc_middle:: bug;
1212use rustc_middle:: ty:: {
13- self , ExistentialPredicateStableCmpExt as _, Instance , InstanceKind , IntTy , List , TraitRef , Ty ,
14- TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt , UintTy ,
13+ self , AssocContainer , ExistentialPredicateStableCmpExt as _, Instance , InstanceKind , IntTy ,
14+ List , TraitRef , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt ,
15+ UintTy ,
1516} ;
1617use rustc_span:: def_id:: DefId ;
1718use rustc_span:: { DUMMY_SP , sym} ;
@@ -466,20 +467,20 @@ fn implemented_method<'tcx>(
466467 let method_id;
467468 let trait_id;
468469 let trait_method;
469- let ancestor = if let Some ( impl_id) = tcx. impl_of_assoc ( instance. def_id ( ) ) {
470- // Implementation in an `impl` block
471- trait_ref = tcx. impl_trait_ref ( impl_id) ?;
472- method_id = tcx. trait_item_of ( instance. def_id ( ) ) ?;
470+ let assoc = tcx. opt_associated_item ( instance. def_id ( ) ) ?;
471+ let ancestor = if let AssocContainer :: TraitImpl ( Ok ( trait_method_id) ) = assoc. container {
472+ let impl_id = tcx. parent ( instance. def_id ( ) ) ;
473+ trait_ref = tcx. impl_trait_ref ( impl_id) . unwrap ( ) ;
474+ method_id = trait_method_id;
473475 trait_method = tcx. associated_item ( method_id) ;
474476 trait_id = trait_ref. skip_binder ( ) . def_id ;
475477 impl_id
476- } else if let InstanceKind :: Item ( def_id ) = instance . def
477- && let Some ( trait_method_bound ) = tcx . opt_associated_item ( def_id )
478+ } else if let AssocContainer :: Trait = assoc . container
479+ && let InstanceKind :: Item ( def_id ) = instance . def
478480 {
479- // Provided method in a `trait` block
480- trait_method = trait_method_bound;
481- method_id = instance. def_id ( ) ;
482- trait_id = tcx. trait_of_assoc ( method_id) ?;
481+ trait_method = assoc;
482+ method_id = def_id;
483+ trait_id = tcx. parent ( method_id) ;
483484 trait_ref = ty:: EarlyBinder :: bind ( TraitRef :: from_assoc ( tcx, trait_id, instance. args ) ) ;
484485 trait_id
485486 } else {
0 commit comments