@@ -809,12 +809,10 @@ impl<'a> LoweringContext<'a> {
809
809
} )
810
810
}
811
811
812
- fn record_body ( & mut self , value : hir:: Expr , decl : Option < & FnDecl > ) -> hir:: BodyId {
812
+ fn record_body ( & mut self , value : hir:: Expr , arguments : HirVec < hir :: Arg > ) -> hir:: BodyId {
813
813
let body = hir:: Body {
814
- arguments : decl. map_or ( hir_vec ! [ ] , |decl| {
815
- decl. inputs . iter ( ) . map ( |x| self . lower_arg ( x) ) . collect ( )
816
- } ) ,
817
814
is_generator : self . is_generator ,
815
+ arguments,
818
816
value,
819
817
} ;
820
818
let id = body. id ( ) ;
@@ -1137,11 +1135,10 @@ impl<'a> LoweringContext<'a> {
1137
1135
capture_clause : CaptureBy ,
1138
1136
closure_node_id : NodeId ,
1139
1137
ret_ty : Option < & Ty > ,
1138
+ span : Span ,
1140
1139
body : impl FnOnce ( & mut LoweringContext < ' _ > ) -> hir:: Expr ,
1141
1140
) -> hir:: ExprKind {
1142
1141
let prev_is_generator = mem:: replace ( & mut self . is_generator , true ) ;
1143
- let body_expr = body ( self ) ;
1144
- let span = body_expr. span ;
1145
1142
let output = match ret_ty {
1146
1143
Some ( ty) => FunctionRetTy :: Ty ( P ( ty. clone ( ) ) ) ,
1147
1144
None => FunctionRetTy :: Default ( span) ,
@@ -1151,7 +1148,11 @@ impl<'a> LoweringContext<'a> {
1151
1148
output,
1152
1149
c_variadic : false
1153
1150
} ;
1154
- let body_id = self . record_body ( body_expr, Some ( & decl) ) ;
1151
+ // Lower the arguments before the body otherwise the body will call `lower_def` expecting
1152
+ // the argument to have been assigned an id already.
1153
+ let arguments = self . lower_args ( Some ( & decl) ) ;
1154
+ let body_expr = body ( self ) ;
1155
+ let body_id = self . record_body ( body_expr, arguments) ;
1155
1156
self . is_generator = prev_is_generator;
1156
1157
1157
1158
let capture_clause = self . lower_capture_clause ( capture_clause) ;
@@ -1182,8 +1183,9 @@ impl<'a> LoweringContext<'a> {
1182
1183
F : FnOnce ( & mut LoweringContext < ' _ > ) -> hir:: Expr ,
1183
1184
{
1184
1185
let prev = mem:: replace ( & mut self . is_generator , false ) ;
1186
+ let arguments = self . lower_args ( decl) ;
1185
1187
let result = f ( self ) ;
1186
- let r = self . record_body ( result, decl ) ;
1188
+ let r = self . record_body ( result, arguments ) ;
1187
1189
self . is_generator = prev;
1188
1190
return r;
1189
1191
}
@@ -2267,6 +2269,10 @@ impl<'a> LoweringContext<'a> {
2267
2269
}
2268
2270
}
2269
2271
2272
+ fn lower_args ( & mut self , decl : Option < & FnDecl > ) -> HirVec < hir:: Arg > {
2273
+ decl. map_or ( hir_vec ! [ ] , |decl| decl. inputs . iter ( ) . map ( |x| self . lower_arg ( x) ) . collect ( ) )
2274
+ }
2275
+
2270
2276
fn lower_arg ( & mut self , arg : & Arg ) -> hir:: Arg {
2271
2277
let LoweredNodeId { node_id : _, hir_id } = self . lower_node_id ( arg. id ) ;
2272
2278
hir:: Arg {
@@ -3045,7 +3051,7 @@ impl<'a> LoweringContext<'a> {
3045
3051
}
3046
3052
3047
3053
let async_expr = this. make_async_expr (
3048
- CaptureBy :: Value , * closure_id, None ,
3054
+ CaptureBy :: Value , * closure_id, None , body . span ,
3049
3055
|this| {
3050
3056
let body = this. lower_block ( & body, false ) ;
3051
3057
this. expr_block ( body, ThinVec :: new ( ) )
@@ -4190,7 +4196,7 @@ impl<'a> LoweringContext<'a> {
4190
4196
hir:: MatchSource :: Normal ,
4191
4197
) ,
4192
4198
ExprKind :: Async ( capture_clause, closure_node_id, ref block) => {
4193
- self . make_async_expr ( capture_clause, closure_node_id, None , |this| {
4199
+ self . make_async_expr ( capture_clause, closure_node_id, None , block . span , |this| {
4194
4200
this. with_new_scopes ( |this| {
4195
4201
let block = this. lower_block ( block, false ) ;
4196
4202
this. expr_block ( block, ThinVec :: new ( ) )
@@ -4236,7 +4242,7 @@ impl<'a> LoweringContext<'a> {
4236
4242
Some ( & * * ty)
4237
4243
} else { None } ;
4238
4244
let async_body = this. make_async_expr (
4239
- capture_clause, * closure_id, async_ret_ty,
4245
+ capture_clause, * closure_id, async_ret_ty, body . span ,
4240
4246
|this| {
4241
4247
this. with_new_scopes ( |this| this. lower_expr ( body) )
4242
4248
} ) ;
0 commit comments