@@ -770,10 +770,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
770
770
body : & Expr ,
771
771
fn_decl_span : Span ,
772
772
) -> hir:: ExprKind < ' hir > {
773
- // Lower outside new scope to preserve `is_in_loop_condition`.
774
- let fn_decl = self . lower_fn_decl ( decl, None , false , None ) ;
775
-
776
- self . with_new_scopes ( move |this| {
773
+ let ( body_id, generator_option) = self . with_new_scopes ( move |this| {
777
774
let prev = this. current_item ;
778
775
this. current_item = Some ( fn_decl_span) ;
779
776
let mut generator_kind = None ;
@@ -785,8 +782,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
785
782
let generator_option =
786
783
this. generator_movability_for_fn ( & decl, fn_decl_span, generator_kind, movability) ;
787
784
this. current_item = prev;
788
- hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, generator_option)
789
- } )
785
+ ( body_id, generator_option)
786
+ } ) ;
787
+
788
+ // Lower outside new scope to preserve `is_in_loop_condition`.
789
+ let fn_decl = self . lower_fn_decl ( decl, None , false , None ) ;
790
+
791
+ hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, generator_option)
790
792
}
791
793
792
794
fn generator_movability_for_fn (
@@ -832,12 +834,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
832
834
) -> hir:: ExprKind < ' hir > {
833
835
let outer_decl =
834
836
FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
835
- // We need to lower the declaration outside the new scope, because we
836
- // have to conserve the state of being inside a loop condition for the
837
- // closure argument types.
838
- let fn_decl = self . lower_fn_decl ( & outer_decl, None , false , None ) ;
839
837
840
- self . with_new_scopes ( move |this| {
838
+ let body_id = self . with_new_scopes ( |this| {
841
839
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
842
840
if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
843
841
struct_span_err ! (
@@ -868,8 +866,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
868
866
) ;
869
867
this. expr ( fn_decl_span, async_body, ThinVec :: new ( ) )
870
868
} ) ;
871
- hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, None )
872
- } )
869
+ body_id
870
+ } ) ;
871
+
872
+ // We need to lower the declaration outside the new scope, because we
873
+ // have to conserve the state of being inside a loop condition for the
874
+ // closure argument types.
875
+ let fn_decl = self . lower_fn_decl ( & outer_decl, None , false , None ) ;
876
+
877
+ hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, None )
873
878
}
874
879
875
880
/// Destructure the LHS of complex assignments.
0 commit comments