@@ -7,7 +7,6 @@ use hir::definitions::DefPathData;
77use rustc_ast:: ptr:: P ;
88use rustc_ast:: visit:: AssocCtxt ;
99use rustc_ast:: * ;
10- use rustc_data_structures:: sorted_map:: SortedMap ;
1110use rustc_errors:: ErrorGuaranteed ;
1211use rustc_hir as hir;
1312use rustc_hir:: def:: { DefKind , Res } ;
@@ -55,42 +54,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
5554 owner : NodeId ,
5655 f : impl FnOnce ( & mut LoweringContext < ' _ , ' hir > ) -> hir:: OwnerNode < ' hir > ,
5756 ) {
58- let allow_gen_future = Some ( if self . tcx . features ( ) . async_fn_track_caller {
59- [ sym:: gen_future, sym:: closure_track_caller] [ ..] . into ( )
60- } else {
61- [ sym:: gen_future] [ ..] . into ( )
62- } ) ;
63- let mut lctx = LoweringContext {
64- // Pseudo-globals.
65- tcx : self . tcx ,
66- resolver : self . resolver ,
67- arena : self . tcx . hir_arena ,
68-
69- // HirId handling.
70- bodies : Vec :: new ( ) ,
71- attrs : SortedMap :: default ( ) ,
72- children : Vec :: default ( ) ,
73- current_hir_id_owner : hir:: CRATE_OWNER_ID ,
74- item_local_id_counter : hir:: ItemLocalId :: new ( 0 ) ,
75- node_id_to_local_id : Default :: default ( ) ,
76- trait_map : Default :: default ( ) ,
77-
78- // Lowering state.
79- catch_scope : None ,
80- loop_scope : None ,
81- is_in_loop_condition : false ,
82- is_in_trait_impl : false ,
83- is_in_dyn_type : false ,
84- coroutine_kind : None ,
85- task_context : None ,
86- current_item : None ,
87- impl_trait_defs : Vec :: new ( ) ,
88- impl_trait_bounds : Vec :: new ( ) ,
89- allow_try_trait : Some ( [ sym:: try_trait_v2, sym:: yeet_desugar_details] [ ..] . into ( ) ) ,
90- allow_gen_future,
91- generics_def_id_map : Default :: default ( ) ,
92- host_param_id : None ,
93- } ;
57+ let mut lctx = LoweringContext :: new ( self . tcx , self . resolver ) ;
9458 lctx. with_hir_id_owner ( owner, |lctx| f ( lctx) ) ;
9559
9660 for ( def_id, info) in lctx. children {
@@ -136,39 +100,9 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
136100
137101 fn lower_assoc_item ( & mut self , item : & AssocItem , ctxt : AssocCtxt ) {
138102 let def_id = self . resolver . node_id_to_def_id [ & item. id ] ;
139-
140103 let parent_id = self . tcx . local_parent ( def_id) ;
141104 let parent_hir = self . lower_node ( parent_id) . unwrap ( ) ;
142- self . with_lctx ( item. id , |lctx| {
143- // Evaluate with the lifetimes in `params` in-scope.
144- // This is used to track which lifetimes have already been defined,
145- // and which need to be replicated when lowering an async fn.
146-
147- match parent_hir. node ( ) . expect_item ( ) . kind {
148- hir:: ItemKind :: Impl ( impl_) => {
149- lctx. is_in_trait_impl = impl_. of_trait . is_some ( ) ;
150- }
151- hir:: ItemKind :: Trait ( _, _, generics, _, _) if lctx. tcx . features ( ) . effects => {
152- lctx. host_param_id = generics
153- . params
154- . iter ( )
155- . find ( |param| {
156- parent_hir
157- . attrs
158- . get ( param. hir_id . local_id )
159- . iter ( )
160- . any ( |attr| attr. has_name ( sym:: rustc_host) )
161- } )
162- . map ( |param| param. def_id ) ;
163- }
164- _ => { }
165- }
166-
167- match ctxt {
168- AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( lctx. lower_trait_item ( item) ) ,
169- AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( lctx. lower_impl_item ( item) ) ,
170- }
171- } )
105+ self . with_lctx ( item. id , |lctx| lctx. lower_assoc_item ( item, ctxt, parent_hir) )
172106 }
173107
174108 fn lower_foreign_item ( & mut self , item : & ForeignItem ) {
@@ -611,6 +545,42 @@ impl<'hir> LoweringContext<'_, 'hir> {
611545 }
612546 }
613547
548+ fn lower_assoc_item (
549+ & mut self ,
550+ item : & AssocItem ,
551+ ctxt : AssocCtxt ,
552+ parent_hir : & ' hir hir:: OwnerInfo < ' hir > ,
553+ ) -> hir:: OwnerNode < ' hir > {
554+ // Evaluate with the lifetimes in `params` in-scope.
555+ // This is used to track which lifetimes have already been defined,
556+ // and which need to be replicated when lowering an async fn.
557+
558+ match parent_hir. node ( ) . expect_item ( ) . kind {
559+ hir:: ItemKind :: Impl ( impl_) => {
560+ self . is_in_trait_impl = impl_. of_trait . is_some ( ) ;
561+ }
562+ hir:: ItemKind :: Trait ( _, _, generics, _, _) if self . tcx . features ( ) . effects => {
563+ self . host_param_id = generics
564+ . params
565+ . iter ( )
566+ . find ( |param| {
567+ parent_hir
568+ . attrs
569+ . get ( param. hir_id . local_id )
570+ . iter ( )
571+ . any ( |attr| attr. has_name ( sym:: rustc_host) )
572+ } )
573+ . map ( |param| param. def_id ) ;
574+ }
575+ _ => { }
576+ }
577+
578+ match ctxt {
579+ AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
580+ AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item) ) ,
581+ }
582+ }
583+
614584 fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> & ' hir hir:: ForeignItem < ' hir > {
615585 let hir_id = self . lower_node_id ( i. id ) ;
616586 let owner_id = hir_id. expect_owner ( ) ;
0 commit comments