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