@@ -75,15 +75,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
75
75
let kind = match & e. kind {
76
76
ExprKind :: Array ( exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
77
77
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 ) ) ,
87
82
} ) ;
88
83
hir:: ExprKind :: ConstBlock ( c)
89
84
}
@@ -382,14 +377,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
382
377
let mut generic_args = ThinVec :: new ( ) ;
383
378
for ( idx, arg) in args. into_iter ( ) . enumerate ( ) {
384
379
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 ;
386
381
let node_id = self . next_node_id ( ) ;
387
382
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
+ ) ;
393
391
394
392
let anon_const = AnonConst { id : node_id, value : arg } ;
395
393
generic_args. push ( AngleBracketedArg :: Arg ( GenericArg :: Const ( anon_const) ) ) ;
@@ -624,7 +622,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
624
622
coroutine_source : hir:: CoroutineSource ,
625
623
body : impl FnOnce ( & mut Self ) -> hir:: Expr < ' hir > ,
626
624
) -> hir:: ExprKind < ' hir > {
627
- let closure_def_id = self . local_def_id ( closure_node_id) ;
628
625
let coroutine_kind = hir:: CoroutineKind :: Desugared ( desugaring_kind, coroutine_source) ;
629
626
630
627
// The `async` desugaring takes a resume argument and maintains a `task_context`,
@@ -675,24 +672,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
675
672
lifetime_elision_allowed : false ,
676
673
} ) ;
677
674
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) ;
681
677
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;
688
684
689
- ( params, res)
690
- } )
685
+ ( params, res)
691
686
} ) ;
692
687
693
688
// `static |<_task_context?>| -> <return_ty> { <body> }`:
694
689
hir:: ExprKind :: Closure ( self . arena . alloc ( hir:: Closure {
695
- def_id : closure_def_id ,
690
+ def_id : self . local_def_id ( closure_node_id ) ,
696
691
binder : hir:: ClosureBinder :: Default ,
697
692
capture_clause,
698
693
bound_generic_params : & [ ] ,
@@ -971,38 +966,35 @@ impl<'hir> LoweringContext<'_, 'hir> {
971
966
fn_decl_span : Span ,
972
967
fn_arg_span : Span ,
973
968
) -> hir:: ExprKind < ' hir > {
974
- let closure_def_id = self . local_def_id ( closure_id) ;
975
969
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
976
970
977
971
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)
998
990
} ) ;
999
991
1000
992
let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
1001
993
// Lower outside new scope to preserve `is_in_loop_condition`.
1002
994
let fn_decl = self . lower_fn_decl ( decl, closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
1003
995
1004
996
let c = self . arena . alloc ( hir:: Closure {
1005
- def_id : closure_def_id ,
997
+ def_id : self . local_def_id ( closure_id ) ,
1006
998
binder : binder_clause,
1007
999
capture_clause,
1008
1000
bound_generic_params,
@@ -1074,7 +1066,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1074
1066
fn_decl_span : Span ,
1075
1067
fn_arg_span : Span ,
1076
1068
) -> hir:: ExprKind < ' hir > {
1077
- let closure_def_id = self . local_def_id ( closure_id) ;
1078
1069
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
1079
1070
1080
1071
assert_matches ! (
@@ -1084,29 +1075,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
1084
1075
) ;
1085
1076
1086
1077
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
+ ) ;
1102
1092
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) ;
1105
1095
1106
- ( parameters, expr)
1107
- } ) ;
1108
- body_id
1109
- } )
1096
+ ( parameters, expr)
1097
+ } ) ;
1098
+ body_id
1110
1099
} ) ;
1111
1100
1112
1101
let bound_generic_params = self . lower_lifetime_binder ( closure_id, generic_params) ;
@@ -1117,7 +1106,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1117
1106
self . lower_fn_decl ( & decl, closure_id, fn_decl_span, FnDeclKind :: Closure , None ) ;
1118
1107
1119
1108
let c = self . arena . alloc ( hir:: Closure {
1120
- def_id : closure_def_id ,
1109
+ def_id : self . local_def_id ( closure_id ) ,
1121
1110
binder : binder_clause,
1122
1111
capture_clause,
1123
1112
bound_generic_params,
0 commit comments