@@ -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 ) {
@@ -408,10 +404,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
408404 ( trait_ref, lowered_ty)
409405 } ) ;
410406
411- self . is_in_trait_impl = trait_ref. is_some ( ) ;
412- let new_impl_items = self
413- . arena
414- . alloc_from_iter ( impl_items. iter ( ) . map ( |item| self . lower_impl_item_ref ( item) ) ) ;
407+ let new_impl_items = self . arena . alloc_from_iter (
408+ impl_items
409+ . iter ( )
410+ . map ( |item| self . lower_impl_item_ref ( item, trait_ref. is_some ( ) ) ) ,
411+ ) ;
415412
416413 // `defaultness.has_value()` is never called for an `impl`, always `true` in order
417414 // to not cause an assertion failure inside the `lower_defaultness` function.
@@ -488,7 +485,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
488485 ItemKind :: Delegation ( box delegation) => {
489486 debug_assert_ne ! ( ident. name, kw:: Empty ) ;
490487 let ident = self . lower_ident ( ident) ;
491- let delegation_results = self . lower_delegation ( delegation, id) ;
488+ let delegation_results = self . lower_delegation ( delegation, id, false ) ;
492489 hir:: ItemKind :: Fn {
493490 ident,
494491 sig : delegation_results. sig ,
@@ -631,29 +628,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
631628 }
632629 }
633630
634- fn lower_assoc_item (
635- & mut self ,
636- item : & AssocItem ,
637- ctxt : AssocCtxt ,
638- parent_hir : & ' hir hir:: OwnerInfo < ' hir > ,
639- ) -> hir:: OwnerNode < ' hir > {
640- let parent_item = parent_hir. node ( ) . expect_item ( ) ;
641- match parent_item. kind {
642- hir:: ItemKind :: Impl ( impl_) => {
643- self . is_in_trait_impl = impl_. of_trait . is_some ( ) ;
644- }
645- hir:: ItemKind :: Trait ( ..) => { }
646- kind => {
647- span_bug ! ( item. span, "assoc item has unexpected kind of parent: {}" , kind. descr( ) )
648- }
649- }
650-
631+ fn lower_assoc_item ( & mut self , item : & AssocItem , ctxt : AssocCtxt ) -> hir:: OwnerNode < ' hir > {
651632 // Evaluate with the lifetimes in `params` in-scope.
652633 // This is used to track which lifetimes have already been defined,
653634 // and which need to be replicated when lowering an async fn.
654635 match ctxt {
655636 AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
656- AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item) ) ,
637+ AssocCtxt :: Impl { of_trait } => {
638+ hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item, of_trait) )
639+ }
657640 }
658641 }
659642
@@ -894,7 +877,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
894877 ( generics, kind, ty. is_some ( ) )
895878 }
896879 AssocItemKind :: Delegation ( box delegation) => {
897- let delegation_results = self . lower_delegation ( delegation, i. id ) ;
880+ let delegation_results = self . lower_delegation ( delegation, i. id , false ) ;
898881 let item_kind = hir:: TraitItemKind :: Fn (
899882 delegation_results. sig ,
900883 hir:: TraitFn :: Provided ( delegation_results. body_id ) ,
@@ -925,7 +908,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
925908 hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
926909 }
927910 AssocItemKind :: Delegation ( box delegation) => hir:: AssocItemKind :: Fn {
928- has_self : self . delegatee_is_method ( i. id , delegation. id , i. span ) ,
911+ has_self : self . delegatee_is_method ( i. id , delegation. id , i. span , false ) ,
929912 } ,
930913 AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
931914 panic ! ( "macros should have been expanded by now" )
@@ -945,7 +928,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
945928 self . expr ( span, hir:: ExprKind :: Err ( guar) )
946929 }
947930
948- fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
931+ fn lower_impl_item (
932+ & mut self ,
933+ i : & AssocItem ,
934+ is_in_trait_impl : bool ,
935+ ) -> & ' hir hir:: ImplItem < ' hir > {
949936 debug_assert_ne ! ( i. ident. name, kw:: Empty ) ;
950937 // Since `default impl` is not yet implemented, this is always true in impls.
951938 let has_value = true ;
@@ -981,7 +968,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
981968 generics,
982969 sig,
983970 i. id ,
984- if self . is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
971+ if is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
985972 sig. header . coroutine_kind ,
986973 attrs,
987974 ) ;
@@ -1021,7 +1008,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10211008 )
10221009 }
10231010 AssocItemKind :: Delegation ( box delegation) => {
1024- let delegation_results = self . lower_delegation ( delegation, i. id ) ;
1011+ let delegation_results = self . lower_delegation ( delegation, i. id , is_in_trait_impl ) ;
10251012 (
10261013 delegation_results. generics ,
10271014 hir:: ImplItemKind :: Fn ( delegation_results. sig , delegation_results. body_id ) ,
@@ -1044,7 +1031,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10441031 self . arena . alloc ( item)
10451032 }
10461033
1047- fn lower_impl_item_ref ( & mut self , i : & AssocItem ) -> hir:: ImplItemRef {
1034+ fn lower_impl_item_ref ( & mut self , i : & AssocItem , is_in_trait_impl : bool ) -> hir:: ImplItemRef {
10481035 hir:: ImplItemRef {
10491036 id : hir:: ImplItemId { owner_id : hir:: OwnerId { def_id : self . local_def_id ( i. id ) } } ,
10501037 ident : self . lower_ident ( i. ident ) ,
@@ -1056,7 +1043,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
10561043 hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
10571044 }
10581045 AssocItemKind :: Delegation ( box delegation) => hir:: AssocItemKind :: Fn {
1059- has_self : self . delegatee_is_method ( i. id , delegation. id , i. span ) ,
1046+ has_self : self . delegatee_is_method (
1047+ i. id ,
1048+ delegation. id ,
1049+ i. span ,
1050+ is_in_trait_impl,
1051+ ) ,
10601052 } ,
10611053 AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
10621054 panic ! ( "macros should have been expanded by now" )
0 commit comments