@@ -404,10 +404,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
404
404
( trait_ref, lowered_ty)
405
405
} ) ;
406
406
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
+ ) ;
411
412
412
413
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
413
414
// to not cause an assertion failure inside the `lower_defaultness` function.
@@ -484,7 +485,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
484
485
ItemKind :: Delegation ( box delegation) => {
485
486
debug_assert_ne ! ( ident. name, kw:: Empty ) ;
486
487
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 ) ;
488
489
hir:: ItemKind :: Fn {
489
490
ident,
490
491
sig : delegation_results. sig ,
@@ -634,10 +635,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
634
635
match ctxt {
635
636
AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
636
637
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) )
641
639
}
642
640
}
643
641
}
@@ -879,7 +877,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
879
877
( generics, kind, ty. is_some ( ) )
880
878
}
881
879
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 ) ;
883
881
let item_kind = hir:: TraitItemKind :: Fn (
884
882
delegation_results. sig ,
885
883
hir:: TraitFn :: Provided ( delegation_results. body_id ) ,
@@ -910,7 +908,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
910
908
hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
911
909
}
912
910
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 ) ,
914
912
} ,
915
913
AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
916
914
panic ! ( "macros should have been expanded by now" )
@@ -930,7 +928,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
930
928
self . expr ( span, hir:: ExprKind :: Err ( guar) )
931
929
}
932
930
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 > {
934
936
debug_assert_ne ! ( i. ident. name, kw:: Empty ) ;
935
937
// Since `default impl` is not yet implemented, this is always true in impls.
936
938
let has_value = true ;
@@ -966,7 +968,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
966
968
generics,
967
969
sig,
968
970
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 } ,
970
972
sig. header . coroutine_kind ,
971
973
attrs,
972
974
) ;
@@ -1006,7 +1008,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1006
1008
)
1007
1009
}
1008
1010
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 ) ;
1010
1012
(
1011
1013
delegation_results. generics ,
1012
1014
hir:: ImplItemKind :: Fn ( delegation_results. sig , delegation_results. body_id ) ,
@@ -1029,7 +1031,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1029
1031
self . arena . alloc ( item)
1030
1032
}
1031
1033
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 {
1033
1035
hir:: ImplItemRef {
1034
1036
id : hir:: ImplItemId { owner_id : hir:: OwnerId { def_id : self . local_def_id ( i. id ) } } ,
1035
1037
ident : self . lower_ident ( i. ident ) ,
@@ -1041,7 +1043,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
1041
1043
hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
1042
1044
}
1043
1045
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
+ ) ,
1045
1052
} ,
1046
1053
AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
1047
1054
panic ! ( "macros should have been expanded by now" )
0 commit comments