@@ -3536,12 +3536,22 @@ impl<'a> LoweringContext<'a> {
35363536                        this. expr_block ( block,  ThinVec :: new ( ) ) 
35373537                    } ) 
35383538                } ) 
3539-             } , 
3539+             } 
35403540            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| { 
35453555                        // FIXME(cramertj) allow `async` non-`move` closures with 
35463556                        if  capture_clause == CaptureBy :: Ref  &&
35473557                            !decl. inputs . is_empty ( ) 
@@ -3561,11 +3571,6 @@ impl<'a> LoweringContext<'a> {
35613571
35623572                        // Transform `async |x: u8| -> X { ... }` into 
35633573                        // `|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-                         } ; 
35693574                        let  body_id = this. lower_body ( Some ( & outer_decl) ,  |this| { 
35703575                            let  async_ret_ty = if  let  FunctionRetTy :: Ty ( ty)  = & decl. output  { 
35713576                                Some ( & * * ty) 
@@ -3579,12 +3584,17 @@ impl<'a> LoweringContext<'a> {
35793584                        } ) ; 
35803585                        hir:: ExprClosure ( 
35813586                            this. lower_capture_clause ( capture_clause) , 
3582-                             this . lower_fn_decl ( & outer_decl ,   None ,   false ,   false ) , 
3587+                             fn_decl , 
35833588                            body_id, 
35843589                            fn_decl_span, 
35853590                            None , 
35863591                        ) 
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| { 
35883598                        let  mut  is_generator = false ; 
35893599                        let  body_id = this. lower_body ( Some ( decl) ,  |this| { 
35903600                            let  e = this. lower_expr ( body) ; 
@@ -3618,13 +3628,13 @@ impl<'a> LoweringContext<'a> {
36183628                        } ; 
36193629                        hir:: ExprClosure ( 
36203630                            this. lower_capture_clause ( capture_clause) , 
3621-                             this . lower_fn_decl ( decl ,   None ,   false ,   false ) , 
3631+                             fn_decl , 
36223632                            body_id, 
36233633                            fn_decl_span, 
36243634                            generator_option, 
36253635                        ) 
3626-                     } 
3627-                 } ) 
3636+                     } ) 
3637+                 } 
36283638            } 
36293639            ExprKind :: Block ( ref  blk,  opt_label)  => { 
36303640                hir:: ExprBlock ( self . lower_block ( blk, 
0 commit comments