@@ -3536,12 +3536,22 @@ impl<'a> LoweringContext<'a> {
3536
3536
this. expr_block ( block, ThinVec :: new ( ) )
3537
3537
} )
3538
3538
} )
3539
- } ,
3539
+ }
3540
3540
ExprKind :: Closure (
3541
- capture_clause, asyncness, movability, ref decl, ref body, fn_decl_span) =>
3542
- {
3543
- self . with_new_scopes ( |this| {
3544
- if let IsAsync :: Async ( async_closure_node_id) = asyncness {
3541
+ capture_clause, asyncness, movability, ref decl, ref body, fn_decl_span
3542
+ ) => {
3543
+ if let IsAsync :: Async ( async_closure_node_id) = asyncness {
3544
+ let outer_decl = FnDecl {
3545
+ inputs : decl. inputs . clone ( ) ,
3546
+ output : FunctionRetTy :: Default ( fn_decl_span) ,
3547
+ variadic : false ,
3548
+ } ;
3549
+ // We need to lower the declaration outside the new scope, because we
3550
+ // have to conserve the state of being inside a loop condition for the
3551
+ // closure argument types.
3552
+ let fn_decl = self . lower_fn_decl ( & outer_decl, None , false , false ) ;
3553
+
3554
+ self . with_new_scopes ( |this| {
3545
3555
// FIXME(cramertj) allow `async` non-`move` closures with
3546
3556
if capture_clause == CaptureBy :: Ref &&
3547
3557
!decl. inputs . is_empty ( )
@@ -3561,11 +3571,6 @@ impl<'a> LoweringContext<'a> {
3561
3571
3562
3572
// Transform `async |x: u8| -> X { ... }` into
3563
3573
// `|x: u8| future_from_generator(|| -> X { ... })`
3564
- let outer_decl = FnDecl {
3565
- inputs : decl. inputs . clone ( ) ,
3566
- output : FunctionRetTy :: Default ( fn_decl_span) ,
3567
- variadic : false ,
3568
- } ;
3569
3574
let body_id = this. lower_body ( Some ( & outer_decl) , |this| {
3570
3575
let async_ret_ty = if let FunctionRetTy :: Ty ( ty) = & decl. output {
3571
3576
Some ( & * * ty)
@@ -3579,12 +3584,17 @@ impl<'a> LoweringContext<'a> {
3579
3584
} ) ;
3580
3585
hir:: ExprClosure (
3581
3586
this. lower_capture_clause ( capture_clause) ,
3582
- this . lower_fn_decl ( & outer_decl , None , false , false ) ,
3587
+ fn_decl ,
3583
3588
body_id,
3584
3589
fn_decl_span,
3585
3590
None ,
3586
3591
)
3587
- } else {
3592
+ } )
3593
+ } else {
3594
+ // Lower outside new scope to preserve `is_in_loop_condition`.
3595
+ let fn_decl = self . lower_fn_decl ( decl, None , false , false ) ;
3596
+
3597
+ self . with_new_scopes ( |this| {
3588
3598
let mut is_generator = false ;
3589
3599
let body_id = this. lower_body ( Some ( decl) , |this| {
3590
3600
let e = this. lower_expr ( body) ;
@@ -3618,13 +3628,13 @@ impl<'a> LoweringContext<'a> {
3618
3628
} ;
3619
3629
hir:: ExprClosure (
3620
3630
this. lower_capture_clause ( capture_clause) ,
3621
- this . lower_fn_decl ( decl , None , false , false ) ,
3631
+ fn_decl ,
3622
3632
body_id,
3623
3633
fn_decl_span,
3624
3634
generator_option,
3625
3635
)
3626
- }
3627
- } )
3636
+ } )
3637
+ }
3628
3638
}
3629
3639
ExprKind :: Block ( ref blk, opt_label) => {
3630
3640
hir:: ExprBlock ( self . lower_block ( blk,
0 commit comments