@@ -70,20 +70,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
70
70
_ => ( ) ,
71
71
}
72
72
73
+ self . create_def_if_needed_for ( e) ;
73
74
let hir_id = self . lower_node_id ( e. id ) ;
74
75
self . lower_attrs ( hir_id, & e. attrs ) ;
75
76
76
77
let kind = match & e. kind {
77
78
ExprKind :: Array ( exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
78
79
ExprKind :: ConstBlock ( c) => {
79
80
let c = self . with_new_scopes ( c. value . span , |this| {
80
- let def_id = this. create_def (
81
- this. current_def_id_parent ,
82
- c. id ,
83
- kw:: Empty ,
84
- DefKind :: InlineConst ,
85
- c. value . span ,
86
- ) ;
81
+ let def_id = this. local_def_id ( c. id ) ;
87
82
hir:: ConstBlock {
88
83
def_id,
89
84
hir_id : this. lower_node_id ( c. id ) ,
@@ -214,13 +209,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
214
209
fn_decl_span,
215
210
fn_arg_span,
216
211
} ) => {
217
- let closure_def = self . create_def (
218
- self . current_def_id_parent ,
219
- e. id ,
220
- kw:: Empty ,
221
- DefKind :: Closure ,
222
- e. span ,
223
- ) ;
212
+ let closure_def = self . local_def_id ( e. id ) ;
224
213
self . with_def_id_parent ( closure_def, |this| match coroutine_kind {
225
214
Some ( coroutine_kind) => this. lower_expr_coroutine_closure (
226
215
binder,
@@ -371,6 +360,34 @@ impl<'hir> LoweringContext<'_, 'hir> {
371
360
} )
372
361
}
373
362
363
+ /// HACK(min_generic_const_args): we delay creation of expression defs until ast_lowering
364
+ ///
365
+ /// This only creates a def for the top-level expression. If it has nested expressions that
366
+ /// need defs, those are handled by the recursion in the main lowering logic.
367
+ fn create_def_if_needed_for ( & mut self , e : & Expr ) {
368
+ match & e. kind {
369
+ ExprKind :: ConstBlock ( c) => {
370
+ self . create_def (
371
+ self . current_def_id_parent ,
372
+ c. id ,
373
+ kw:: Empty ,
374
+ DefKind :: InlineConst ,
375
+ c. value . span ,
376
+ ) ;
377
+ }
378
+ ExprKind :: Closure ( _) => {
379
+ self . create_def (
380
+ self . current_def_id_parent ,
381
+ e. id ,
382
+ kw:: Empty ,
383
+ DefKind :: Closure ,
384
+ e. span ,
385
+ ) ;
386
+ }
387
+ _ => { }
388
+ }
389
+ }
390
+
374
391
fn lower_unop ( & mut self , u : UnOp ) -> hir:: UnOp {
375
392
match u {
376
393
UnOp :: Deref => hir:: UnOp :: Deref ,
0 commit comments