@@ -7,7 +7,6 @@ use rustc_hir::def::{DefKind, Res};
7
7
use rustc_hir:: def_id:: { CRATE_DEF_ID , LocalDefId } ;
8
8
use rustc_hir:: { self as hir, HirId , PredicateOrigin } ;
9
9
use rustc_index:: { IndexSlice , IndexVec } ;
10
- use rustc_middle:: span_bug;
11
10
use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
12
11
use rustc_span:: edit_distance:: find_best_match_for_name;
13
12
use rustc_span:: { DUMMY_SP , DesugaringKind , Ident , Span , Symbol , kw, sym} ;
@@ -104,10 +103,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
104
103
}
105
104
106
105
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) )
111
107
}
112
108
113
109
fn lower_foreign_item ( & mut self , item : & ForeignItem ) {
@@ -405,10 +401,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
405
401
( trait_ref, lowered_ty)
406
402
} ) ;
407
403
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
+ ) ;
412
409
413
410
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
414
411
// to not cause an assertion failure inside the `lower_defaultness` function.
@@ -485,7 +482,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
485
482
ItemKind :: Delegation ( box delegation) => {
486
483
debug_assert_ne ! ( ident. name, kw:: Empty ) ;
487
484
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 ) ;
489
486
hir:: ItemKind :: Fn {
490
487
ident,
491
488
sig : delegation_results. sig ,
@@ -628,29 +625,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
628
625
}
629
626
}
630
627
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 > {
648
629
// Evaluate with the lifetimes in `params` in-scope.
649
630
// This is used to track which lifetimes have already been defined,
650
631
// and which need to be replicated when lowering an async fn.
651
632
match ctxt {
652
633
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
+ }
654
637
}
655
638
}
656
639
@@ -891,7 +874,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
891
874
( generics, kind, ty. is_some ( ) )
892
875
}
893
876
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 ) ;
895
878
let item_kind = hir:: TraitItemKind :: Fn (
896
879
delegation_results. sig ,
897
880
hir:: TraitFn :: Provided ( delegation_results. body_id ) ,
@@ -922,7 +905,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
922
905
hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
923
906
}
924
907
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 ) ,
926
909
} ,
927
910
AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
928
911
panic ! ( "macros should have been expanded by now" )
@@ -942,7 +925,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
942
925
self . expr ( span, hir:: ExprKind :: Err ( guar) )
943
926
}
944
927
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 > {
946
933
debug_assert_ne ! ( i. ident. name, kw:: Empty ) ;
947
934
// Since `default impl` is not yet implemented, this is always true in impls.
948
935
let has_value = true ;
@@ -978,7 +965,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
978
965
generics,
979
966
sig,
980
967
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 } ,
982
969
sig. header . coroutine_kind ,
983
970
attrs,
984
971
) ;
@@ -1018,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1018
1005
)
1019
1006
}
1020
1007
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 ) ;
1022
1009
(
1023
1010
delegation_results. generics ,
1024
1011
hir:: ImplItemKind :: Fn ( delegation_results. sig , delegation_results. body_id ) ,
@@ -1041,7 +1028,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1041
1028
self . arena . alloc ( item)
1042
1029
}
1043
1030
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 {
1045
1032
hir:: ImplItemRef {
1046
1033
id : hir:: ImplItemId { owner_id : self . owner_id ( i. id ) } ,
1047
1034
ident : self . lower_ident ( i. ident ) ,
@@ -1053,7 +1040,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
1053
1040
hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
1054
1041
}
1055
1042
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
+ ) ,
1057
1049
} ,
1058
1050
AssocItemKind :: MacCall ( ..) | AssocItemKind :: DelegationMac ( ..) => {
1059
1051
panic ! ( "macros should have been expanded by now" )
0 commit comments