@@ -404,10 +404,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
404404 ( trait_ref, lowered_ty)
405405 } ) ;
406406
407- self . is_in_trait_impl = trait_ref. is_some ( ) ;
408- let new_impl_items = self
409- . arena
410- . 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+ ) ;
411412
412413 // `defaultness.has_value()` is never called for an `impl`, always `true` in order
413414 // to not cause an assertion failure inside the `lower_defaultness` function.
@@ -484,7 +485,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
484485 ItemKind :: Delegation ( box delegation) => {
485486 debug_assert_ne ! ( ident. name, kw:: Empty ) ;
486487 let ident = self . lower_ident ( ident) ;
487- let delegation_results = self . lower_delegation ( delegation, id) ;
488+ let delegation_results = self . lower_delegation ( delegation, id, false ) ;
488489 hir:: ItemKind :: Fn {
489490 ident,
490491 sig : delegation_results. sig ,
@@ -634,10 +635,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
634635 match ctxt {
635636 AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
636637 AssocCtxt :: Impl { of_trait } => {
637- if of_trait {
638- self . is_in_trait_impl = of_trait;
639- }
640- hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item) )
638+ hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item, of_trait) )
641639 }
642640 }
643641 }
@@ -879,7 +877,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
879877 ( generics, kind, ty. is_some ( ) )
880878 }
881879 AssocItemKind :: Delegation ( box delegation) => {
882- let delegation_results = self . lower_delegation ( delegation, i. id ) ;
880+ let delegation_results = self . lower_delegation ( delegation, i. id , false ) ;
883881 let item_kind = hir:: TraitItemKind :: Fn (
884882 delegation_results. sig ,
885883 hir:: TraitFn :: Provided ( delegation_results. body_id ) ,
@@ -910,7 +908,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
910908 hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
911909 }
912910 AssocItemKind :: Delegation ( box delegation) => hir:: AssocItemKind :: Fn {
913- 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 ) ,
914912 } ,
915913 AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
916914 panic ! ( "macros should have been expanded by now" )
@@ -930,7 +928,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
930928 self . expr ( span, hir:: ExprKind :: Err ( guar) )
931929 }
932930
933- 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 > {
934936 debug_assert_ne ! ( i. ident. name, kw:: Empty ) ;
935937 // Since `default impl` is not yet implemented, this is always true in impls.
936938 let has_value = true ;
@@ -966,7 +968,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
966968 generics,
967969 sig,
968970 i. id ,
969- if self . is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
971+ if is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
970972 sig. header . coroutine_kind ,
971973 attrs,
972974 ) ;
@@ -1006,7 +1008,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10061008 )
10071009 }
10081010 AssocItemKind :: Delegation ( box delegation) => {
1009- let delegation_results = self . lower_delegation ( delegation, i. id ) ;
1011+ let delegation_results = self . lower_delegation ( delegation, i. id , is_in_trait_impl ) ;
10101012 (
10111013 delegation_results. generics ,
10121014 hir:: ImplItemKind :: Fn ( delegation_results. sig , delegation_results. body_id ) ,
@@ -1029,7 +1031,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10291031 self . arena . alloc ( item)
10301032 }
10311033
1032- 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 {
10331035 hir:: ImplItemRef {
10341036 id : hir:: ImplItemId { owner_id : hir:: OwnerId { def_id : self . local_def_id ( i. id ) } } ,
10351037 ident : self . lower_ident ( i. ident ) ,
@@ -1041,7 +1043,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
10411043 hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
10421044 }
10431045 AssocItemKind :: Delegation ( box delegation) => hir:: AssocItemKind :: Fn {
1044- 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+ ) ,
10451052 } ,
10461053 AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
10471054 panic ! ( "macros should have been expanded by now" )
0 commit comments