@@ -7,7 +7,6 @@ use rustc_hir::def::{DefKind, Res};
77use rustc_hir:: def_id:: { CRATE_DEF_ID , LocalDefId } ;
88use rustc_hir:: { self as hir, HirId , PredicateOrigin } ;
99use rustc_index:: { IndexSlice , IndexVec } ;
10- use rustc_middle:: span_bug;
1110use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
1211use rustc_span:: edit_distance:: find_best_match_for_name;
1312use rustc_span:: { DUMMY_SP , DesugaringKind , Ident , Span , Symbol , kw, sym} ;
@@ -104,10 +103,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
104103 }
105104
106105 fn lower_assoc_item ( & mut self , item : & AssocItem , ctxt : AssocCtxt ) {
107- let def_id = self . resolver . node_id_to_def_id [ & item. id ] ;
108- let parent_id = self . tcx . local_parent ( def_id) ;
109- let parent_hir = self . lower_node ( parent_id) . unwrap ( ) ;
110- self . with_lctx ( item. id , |lctx| lctx. lower_assoc_item ( item, ctxt, parent_hir) )
106+ self . with_lctx ( item. id , |lctx| lctx. lower_assoc_item ( item, ctxt) )
111107 }
112108
113109 fn lower_foreign_item ( & mut self , item : & ForeignItem ) {
@@ -405,10 +401,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
405401 ( trait_ref, lowered_ty)
406402 } ) ;
407403
408- self . is_in_trait_impl = trait_ref. is_some ( ) ;
409- let new_impl_items = self
410- . arena
411- . alloc_from_iter ( impl_items. iter ( ) . map ( |item| self . lower_impl_item_ref ( item) ) ) ;
404+ let new_impl_items = self . arena . alloc_from_iter (
405+ impl_items
406+ . iter ( )
407+ . map ( |item| self . lower_impl_item_ref ( item, trait_ref. is_some ( ) ) ) ,
408+ ) ;
412409
413410 // `defaultness.has_value()` is never called for an `impl`, always `true` in order
414411 // to not cause an assertion failure inside the `lower_defaultness` function.
@@ -485,7 +482,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
485482 ItemKind :: Delegation ( box delegation) => {
486483 debug_assert_ne ! ( ident. name, kw:: Empty ) ;
487484 let ident = self . lower_ident ( ident) ;
488- let delegation_results = self . lower_delegation ( delegation, id) ;
485+ let delegation_results = self . lower_delegation ( delegation, id, false ) ;
489486 hir:: ItemKind :: Fn {
490487 ident,
491488 sig : delegation_results. sig ,
@@ -628,29 +625,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
628625 }
629626 }
630627
631- fn lower_assoc_item (
632- & mut self ,
633- item : & AssocItem ,
634- ctxt : AssocCtxt ,
635- parent_hir : & ' hir hir:: OwnerInfo < ' hir > ,
636- ) -> hir:: OwnerNode < ' hir > {
637- let parent_item = parent_hir. node ( ) . expect_item ( ) ;
638- match parent_item. kind {
639- hir:: ItemKind :: Impl ( impl_) => {
640- self . is_in_trait_impl = impl_. of_trait . is_some ( ) ;
641- }
642- hir:: ItemKind :: Trait ( ..) => { }
643- kind => {
644- span_bug ! ( item. span, "assoc item has unexpected kind of parent: {}" , kind. descr( ) )
645- }
646- }
647-
628+ fn lower_assoc_item ( & mut self , item : & AssocItem , ctxt : AssocCtxt ) -> hir:: OwnerNode < ' hir > {
648629 // Evaluate with the lifetimes in `params` in-scope.
649630 // This is used to track which lifetimes have already been defined,
650631 // and which need to be replicated when lowering an async fn.
651632 match ctxt {
652633 AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
653- AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item) ) ,
634+ AssocCtxt :: Impl { of_trait } => {
635+ hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item, of_trait) )
636+ }
654637 }
655638 }
656639
@@ -891,7 +874,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
891874 ( generics, kind, ty. is_some ( ) )
892875 }
893876 AssocItemKind :: Delegation ( box delegation) => {
894- let delegation_results = self . lower_delegation ( delegation, i. id ) ;
877+ let delegation_results = self . lower_delegation ( delegation, i. id , false ) ;
895878 let item_kind = hir:: TraitItemKind :: Fn (
896879 delegation_results. sig ,
897880 hir:: TraitFn :: Provided ( delegation_results. body_id ) ,
@@ -922,7 +905,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
922905 hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
923906 }
924907 AssocItemKind :: Delegation ( box delegation) => hir:: AssocItemKind :: Fn {
925- has_self : self . delegatee_is_method ( i. id , delegation. id , i. span ) ,
908+ has_self : self . delegatee_is_method ( i. id , delegation. id , i. span , false ) ,
926909 } ,
927910 AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
928911 panic ! ( "macros should have been expanded by now" )
@@ -942,7 +925,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
942925 self . expr ( span, hir:: ExprKind :: Err ( guar) )
943926 }
944927
945- fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
928+ fn lower_impl_item (
929+ & mut self ,
930+ i : & AssocItem ,
931+ is_in_trait_impl : bool ,
932+ ) -> & ' hir hir:: ImplItem < ' hir > {
946933 debug_assert_ne ! ( i. ident. name, kw:: Empty ) ;
947934 // Since `default impl` is not yet implemented, this is always true in impls.
948935 let has_value = true ;
@@ -978,7 +965,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
978965 generics,
979966 sig,
980967 i. id ,
981- if self . is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
968+ if is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
982969 sig. header . coroutine_kind ,
983970 attrs,
984971 ) ;
@@ -1018,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10181005 )
10191006 }
10201007 AssocItemKind :: Delegation ( box delegation) => {
1021- let delegation_results = self . lower_delegation ( delegation, i. id ) ;
1008+ let delegation_results = self . lower_delegation ( delegation, i. id , is_in_trait_impl ) ;
10221009 (
10231010 delegation_results. generics ,
10241011 hir:: ImplItemKind :: Fn ( delegation_results. sig , delegation_results. body_id ) ,
@@ -1041,7 +1028,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10411028 self . arena . alloc ( item)
10421029 }
10431030
1044- fn lower_impl_item_ref ( & mut self , i : & AssocItem ) -> hir:: ImplItemRef {
1031+ fn lower_impl_item_ref ( & mut self , i : & AssocItem , is_in_trait_impl : bool ) -> hir:: ImplItemRef {
10451032 hir:: ImplItemRef {
10461033 id : hir:: ImplItemId { owner_id : self . owner_id ( i. id ) } ,
10471034 ident : self . lower_ident ( i. ident ) ,
@@ -1053,7 +1040,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
10531040 hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
10541041 }
10551042 AssocItemKind :: Delegation ( box delegation) => hir:: AssocItemKind :: Fn {
1056- has_self : self . delegatee_is_method ( i. id , delegation. id , i. span ) ,
1043+ has_self : self . delegatee_is_method (
1044+ i. id ,
1045+ delegation. id ,
1046+ i. span ,
1047+ is_in_trait_impl,
1048+ ) ,
10571049 } ,
10581050 AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
10591051 panic ! ( "macros should have been expanded by now" )
0 commit comments