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