@@ -60,8 +60,9 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
6060use rustc_hir:: definitions:: PerParentDisambiguatorState ;
6161use rustc_hir:: lints:: DelayedLint ;
6262use rustc_hir:: {
63- self as hir, AngleBrackets , ConstArg , GenericArg , HirId , ItemLocalMap , LifetimeSource ,
64- LifetimeSyntax , MissingLifetimeKind , ParamName , Target , TraitCandidate , find_attr,
63+ self as hir, AngleBrackets , CRATE_OWNER_ID , ConstArg , GenericArg , HirId , ItemLocalMap ,
64+ LifetimeSource , LifetimeSyntax , MissingLifetimeKind , ParamName , Target , TraitCandidate ,
65+ find_attr,
6566} ;
6667use rustc_index:: { Idx , IndexSlice , IndexVec } ;
6768use rustc_macros:: extension;
@@ -296,7 +297,7 @@ struct LoweringContext<'a, 'hir> {
296297
297298 /// Used to get the current `fn`'s def span to point to when using `await`
298299 /// outside of an `async fn`.
299- current_item : Option < Span > ,
300+ current_item_span : Option < Span > ,
300301
301302 try_block_scope : TryBlockScope ,
302303 loop_scope : Option < HirId > ,
@@ -366,7 +367,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
366367 is_in_dyn_type : false ,
367368 coroutine_kind : None ,
368369 task_context : None ,
369- current_item : None ,
370+ current_item_span : None ,
370371
371372 move_expr_bindings : Vec :: new ( ) ,
372373 lowering_move_expr_initializer : false ,
@@ -783,15 +784,37 @@ fn lower_to_hir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::MaybeOwner<'_> {
783784 return fallback_to_ancestor ( tcx. local_parent ( def_id) ) ;
784785 } ;
785786
786- let mut item_lowerer = item:: ItemLowerer { tcx, resolver : & * resolver } ;
787+ fn with_lctx < ' hir > (
788+ tcx : TyCtxt < ' hir > ,
789+ resolver : & ResolverAstLowering < ' hir > ,
790+ owner : NodeId ,
791+ f : impl FnOnce ( & mut LoweringContext < ' _ , ' hir > ) -> hir:: OwnerNode < ' hir > ,
792+ ) -> hir:: MaybeOwner < ' hir > {
793+ let mut lctx = LoweringContext :: new ( tcx, resolver, owner) ;
794+ let item = f ( & mut lctx) ;
795+ hir:: MaybeOwner :: Owner ( lctx. curr_owner . into_owner_info ( tcx, item) )
796+ }
787797
788798 let item = match & node {
789799 // The item existed in the AST.
790- AstOwner :: Crate ( c) => item_lowerer. lower_crate ( & c) ,
791- AstOwner :: Item ( item) => item_lowerer. lower_item ( & item) ,
792- AstOwner :: TraitItem ( item) => item_lowerer. lower_trait_item ( & item) ,
793- AstOwner :: ImplItem ( item) => item_lowerer. lower_impl_item ( & item) ,
794- AstOwner :: ForeignItem ( item) => item_lowerer. lower_foreign_item ( & item) ,
800+ AstOwner :: Crate ( c) => with_lctx ( tcx, & * resolver, CRATE_NODE_ID , |lctx| {
801+ debug_assert_eq ! ( lctx. curr_owner. owner_id( ) , CRATE_OWNER_ID ) ;
802+ let module = lctx. lower_mod ( & c. items , & c. spans ) ;
803+ lctx. lower_attrs ( hir:: CRATE_HIR_ID , & c. attrs , c. spans . inner_span , Target :: Crate ) ;
804+ hir:: OwnerNode :: Crate ( module)
805+ } ) ,
806+ AstOwner :: Item ( item) => {
807+ with_lctx ( tcx, & * resolver, item. id , |lctx| hir:: OwnerNode :: Item ( lctx. lower_item ( item) ) )
808+ }
809+ AstOwner :: TraitItem ( item) => with_lctx ( tcx, & * resolver, item. id , |lctx| {
810+ hir:: OwnerNode :: TraitItem ( lctx. lower_trait_item ( item) )
811+ } ) ,
812+ AstOwner :: ImplItem ( item) => with_lctx ( tcx, & * resolver, item. id , |lctx| {
813+ hir:: OwnerNode :: ImplItem ( lctx. lower_impl_item ( item) )
814+ } ) ,
815+ AstOwner :: ForeignItem ( item) => with_lctx ( tcx, & * resolver, item. id , |lctx| {
816+ hir:: OwnerNode :: ForeignItem ( lctx. lower_foreign_item ( item) )
817+ } ) ,
795818 AstOwner :: NestedUseTree ( owner_id) => fallback_to_ancestor ( * owner_id) ,
796819 // The item existed in the AST, but is not a HIR owner.
797820 // Fetch the correct information from its parent.
@@ -824,7 +847,7 @@ enum GenericArgsMode {
824847 ParenSugar ,
825848 /// Allow RTN, don't allow paren sugar.
826849 ReturnTypeNotation ,
827- // Error if parenthesized generics or RTN are encountered.
850+ /// Error if parenthesized generics or RTN are encountered.
828851 Err ,
829852 /// Silence errors when lowering generics. Only used with `Res::Err`.
830853 Silence ,
@@ -982,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9821005 }
9831006
9841007 #[ instrument( level = "trace" , skip( self ) ) ]
985- fn lower_res ( & mut self , res : Res < NodeId > ) -> Res {
1008+ fn lower_res ( & self , res : Res < NodeId > ) -> Res {
9861009 let res: Result < Res , ( ) > = res. apply_id ( |id| {
9871010 let owner = self . curr_owner . owner_id ( ) ;
9881011 let local_id =
@@ -999,11 +1022,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
9991022 res. unwrap_or ( Res :: Err )
10001023 }
10011024
1002- fn expect_full_res ( & mut self , id : NodeId ) -> Res < NodeId > {
1025+ fn expect_full_res ( & self , id : NodeId ) -> Res < NodeId > {
10031026 self . get_partial_res ( id) . map_or ( Res :: Err , |pr| pr. expect_full_res ( ) )
10041027 }
10051028
1006- fn lower_import_res ( & mut self , id : NodeId , span : Span ) -> PerNS < Option < Res > > {
1029+ fn lower_import_res ( & self , id : NodeId , span : Span ) -> PerNS < Option < Res > > {
10071030 debug_assert_eq ! ( id, self . curr_owner. owner. id) ;
10081031 let per_ns = self . curr_owner . owner . import_res . map ( |res| res. map ( |res| self . lower_res ( res) ) ) ;
10091032 if per_ns. is_empty ( ) {
@@ -1154,8 +1177,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11541177 }
11551178
11561179 fn with_new_scopes < T > ( & mut self , scope_span : Span , f : impl FnOnce ( & mut Self ) -> T ) -> T {
1157- let current_item = self . current_item ;
1158- self . current_item = Some ( scope_span) ;
1180+ let current_item_span = self . current_item_span ;
1181+ self . current_item_span = Some ( scope_span) ;
11591182
11601183 let was_in_loop_condition = self . is_in_loop_condition ;
11611184 self . is_in_loop_condition = false ;
@@ -1172,7 +1195,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11721195
11731196 self . is_in_loop_condition = was_in_loop_condition;
11741197
1175- self . current_item = current_item ;
1198+ self . current_item_span = current_item_span ;
11761199
11771200 ret
11781201 }
@@ -1261,10 +1284,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
12611284 }
12621285 }
12631286
1264- fn lower_delim_args ( & self , args : & DelimArgs ) -> DelimArgs {
1265- args. clone ( )
1266- }
1267-
12681287 /// Lower an associated item constraint.
12691288 #[ instrument( level = "debug" , skip_all) ]
12701289 fn lower_assoc_item_constraint (
@@ -1647,8 +1666,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
16471666 self . lower_array_length_to_const_arg ( length) ,
16481667 ) ,
16491668 TyKind :: TraitObject ( bounds, kind) => {
1650- let mut lifetime_bound = None ;
16511669 let ( bounds, lifetime_bound) = self . with_dyn_type_scope ( true , |this| {
1670+ let mut lifetime_bound = None ;
16521671 let bounds =
16531672 this. arena . alloc_from_iter ( bounds. iter ( ) . filter_map ( |bound| match bound {
16541673 // We can safely ignore constness here since AST validation
@@ -1681,9 +1700,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16811700 None
16821701 }
16831702 } ) ) ;
1684- let lifetime_bound =
1685- lifetime_bound. unwrap_or_else ( || this. elided_dyn_bound ( t. span ) ) ;
1686- ( bounds, lifetime_bound)
1703+ ( bounds, lifetime_bound. unwrap_or_else ( || this. elided_dyn_bound ( t. span ) ) )
16871704 } ) ;
16881705 hir:: TyKind :: TraitObject ( bounds, TaggedRef :: new ( lifetime_bound, * kind) )
16891706 }
@@ -3058,15 +3075,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
30583075 } ) )
30593076 }
30603077
3061- fn lower_unsafe_source ( & mut self , u : UnsafeSource ) -> hir:: UnsafeSource {
3078+ fn lower_unsafe_source ( & self , u : UnsafeSource ) -> hir:: UnsafeSource {
30623079 match u {
30633080 CompilerGenerated => hir:: UnsafeSource :: CompilerGenerated ,
30643081 UserProvided => hir:: UnsafeSource :: UserProvided ,
30653082 }
30663083 }
30673084
30683085 fn lower_trait_bound_modifiers (
3069- & mut self ,
3086+ & self ,
30703087 modifiers : TraitBoundModifiers ,
30713088 ) -> hir:: TraitBoundModifiers {
30723089 let constness = match modifiers. constness {
0 commit comments