@@ -75,15 +75,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
7575 let kind = match & e. kind {
7676 ExprKind :: Array ( exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
7777 ExprKind :: ConstBlock ( c) => {
78- let c = self . with_new_scopes ( c. value . span , |this| {
79- let def_id = this. local_def_id ( c. id ) ;
80- hir:: ConstBlock {
81- def_id,
82- hir_id : this. lower_node_id ( c. id ) ,
83- body : this. with_def_id_parent ( def_id, |this| {
84- this. lower_const_body ( c. value . span , Some ( & c. value ) )
85- } ) ,
86- }
78+ let c = self . with_new_scopes ( c. value . span , |this| hir:: ConstBlock {
79+ def_id : this. local_def_id ( c. id ) ,
80+ hir_id : this. lower_node_id ( c. id ) ,
81+ body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
8782 } ) ;
8883 hir:: ExprKind :: ConstBlock ( c)
8984 }
@@ -382,14 +377,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
382377 let mut generic_args = ThinVec :: new ( ) ;
383378 for ( idx, arg) in args. into_iter ( ) . enumerate ( ) {
384379 if legacy_args_idx. contains ( & idx) {
385- let parent_def_id = self . current_def_id_parent ;
380+ let parent_def_id = self . current_hir_id_owner ;
386381 let node_id = self . next_node_id ( ) ;
387382
388- // HACK(min_generic_const_args): see lower_anon_const
389- if !arg. is_potential_trivial_const_arg ( ) {
390- // Add a definition for the in-band const def.
391- self . create_def ( parent_def_id, node_id, kw:: Empty , DefKind :: AnonConst , f. span ) ;
392- }
383+ // Add a definition for the in-band const def.
384+ self . create_def (
385+ parent_def_id. def_id ,
386+ node_id,
387+ kw:: Empty ,
388+ DefKind :: AnonConst ,
389+ f. span ,
390+ ) ;
393391
394392 let anon_const = AnonConst { id : node_id, value : arg } ;
395393 generic_args. push ( AngleBracketedArg :: Arg ( GenericArg :: Const ( anon_const) ) ) ;
@@ -624,7 +622,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
624622 coroutine_source : hir:: CoroutineSource ,
625623 body : impl FnOnce ( & mut Self ) -> hir:: Expr < ' hir > ,
626624 ) -> hir:: ExprKind < ' hir > {
627- let closure_def_id = self . local_def_id ( closure_node_id) ;
628625 let coroutine_kind = hir:: CoroutineKind :: Desugared ( desugaring_kind, coroutine_source) ;
629626
630627 // The `async` desugaring takes a resume argument and maintains a `task_context`,
@@ -675,24 +672,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
675672 lifetime_elision_allowed : false ,
676673 } ) ;
677674
678- let body = self . with_def_id_parent ( closure_def_id, move |this| {
679- this. lower_body ( move |this| {
680- this. coroutine_kind = Some ( coroutine_kind) ;
675+ let body = self . lower_body ( move |this| {
676+ this. coroutine_kind = Some ( coroutine_kind) ;
681677
682- let old_ctx = this. task_context ;
683- if task_context. is_some ( ) {
684- this. task_context = task_context;
685- }
686- let res = body ( this) ;
687- this. task_context = old_ctx;
678+ let old_ctx = this. task_context ;
679+ if task_context. is_some ( ) {
680+ this. task_context = task_context;
681+ }
682+ let res = body ( this) ;
683+ this. task_context = old_ctx;
688684
689- ( params, res)
690- } )
685+ ( params, res)
691686 } ) ;
692687
693688 // `static |<_task_context?>| -> <return_ty> { <body> }`:
694689 hir:: ExprKind :: Closure ( self . arena . alloc ( hir:: Closure {
695- def_id : closure_def_id ,
690+ def_id : self . local_def_id ( closure_node_id ) ,
696691 binder : hir:: ClosureBinder :: Default ,
697692 capture_clause,
698693 bound_generic_params : & [ ] ,
@@ -971,38 +966,35 @@ impl<'hir> LoweringContext<'_, 'hir> {
971966 fn_decl_span : Span ,
972967 fn_arg_span : Span ,
973968 ) -> hir:: ExprKind < ' hir > {
974- let closure_def_id = self . local_def_id ( closure_id) ;
975969 let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
976970
977971 let ( body_id, closure_kind) = self . with_new_scopes ( fn_decl_span, move |this| {
978- this. with_def_id_parent ( closure_def_id, move |this| {
979- let mut coroutine_kind = if this
980- . attrs
981- . get ( & closure_hir_id. local_id )
982- . is_some_and ( |attrs| attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: coroutine) ) )
983- {
984- Some ( hir:: CoroutineKind :: Coroutine ( Movability :: Movable ) )
985- } else {
986- None
987- } ;
988- let body_id = this. lower_fn_body ( decl, |this| {
989- this. coroutine_kind = coroutine_kind;
990- let e = this. lower_expr_mut ( body) ;
991- coroutine_kind = this. coroutine_kind ;
992- e
993- } ) ;
994- let coroutine_option =
995- this. closure_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
996- ( body_id, coroutine_option)
997- } )
972+ let mut coroutine_kind = if this
973+ . attrs
974+ . get ( & closure_hir_id. local_id )
975+ . is_some_and ( |attrs| attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: coroutine) ) )
976+ {
977+ Some ( hir:: CoroutineKind :: Coroutine ( Movability :: Movable ) )
978+ } else {
979+ None
980+ } ;
981+ let body_id = this. lower_fn_body ( decl, |this| {
982+ this. coroutine_kind = coroutine_kind;
983+ let e = this. lower_expr_mut ( body) ;
984+ coroutine_kind = this. coroutine_kind ;
985+ e
986+ } ) ;
987+ let coroutine_option =
988+ this. closure_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
989+ ( body_id, coroutine_option)
998990 } ) ;
999991
1000992 let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
1001993 // Lower outside new scope to preserve `is_in_loop_condition`.
1002994 let fn_decl = self . lower_fn_decl ( decl, closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
1003995
1004996 let c = self . arena . alloc ( hir:: Closure {
1005- def_id : closure_def_id ,
997+ def_id : self . local_def_id ( closure_id ) ,
1006998 binder : binder_clause,
1007999 capture_clause,
10081000 bound_generic_params,
@@ -1074,7 +1066,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
10741066 fn_decl_span : Span ,
10751067 fn_arg_span : Span ,
10761068 ) -> hir:: ExprKind < ' hir > {
1077- let closure_def_id = self . local_def_id ( closure_id) ;
10781069 let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
10791070
10801071 assert_matches ! (
@@ -1084,29 +1075,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
10841075 ) ;
10851076
10861077 let body = self . with_new_scopes ( fn_decl_span, |this| {
1087- this. with_def_id_parent ( closure_def_id, |this| {
1088- let inner_decl =
1089- FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1090-
1091- // Transform `async |x: u8| -> X { ... }` into
1092- // `|x: u8| || -> X { ... }`.
1093- let body_id = this. lower_body ( |this| {
1094- let ( parameters, expr) = this. lower_coroutine_body_with_moved_arguments (
1095- & inner_decl,
1096- |this| this. with_new_scopes ( fn_decl_span, |this| this. lower_expr_mut ( body) ) ,
1097- fn_decl_span,
1098- body. span ,
1099- coroutine_kind,
1100- hir:: CoroutineSource :: Closure ,
1101- ) ;
1078+ let inner_decl =
1079+ FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
1080+
1081+ // Transform `async |x: u8| -> X { ... }` into
1082+ // `|x: u8| || -> X { ... }`.
1083+ let body_id = this. lower_body ( |this| {
1084+ let ( parameters, expr) = this. lower_coroutine_body_with_moved_arguments (
1085+ & inner_decl,
1086+ |this| this. with_new_scopes ( fn_decl_span, |this| this. lower_expr_mut ( body) ) ,
1087+ fn_decl_span,
1088+ body. span ,
1089+ coroutine_kind,
1090+ hir:: CoroutineSource :: Closure ,
1091+ ) ;
11021092
1103- let hir_id = this. lower_node_id ( coroutine_kind. closure_id ( ) ) ;
1104- this. maybe_forward_track_caller ( body. span , closure_hir_id, hir_id) ;
1093+ let hir_id = this. lower_node_id ( coroutine_kind. closure_id ( ) ) ;
1094+ this. maybe_forward_track_caller ( body. span , closure_hir_id, hir_id) ;
11051095
1106- ( parameters, expr)
1107- } ) ;
1108- body_id
1109- } )
1096+ ( parameters, expr)
1097+ } ) ;
1098+ body_id
11101099 } ) ;
11111100
11121101 let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
@@ -1117,7 +1106,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11171106 self . lower_fn_decl ( & decl, closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
11181107
11191108 let c = self . arena . alloc ( hir:: Closure {
1120- def_id : closure_def_id ,
1109+ def_id : self . local_def_id ( closure_id ) ,
11211110 binder : binder_clause,
11221111 capture_clause,
11231112 bound_generic_params,
0 commit comments