@@ -776,10 +776,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
776
776
body : & Expr ,
777
777
fn_decl_span : Span ,
778
778
) -> hir:: ExprKind < ' hir > {
779
- // Lower outside new scope to preserve `is_in_loop_condition`.
780
- let fn_decl = self . lower_fn_decl ( decl, None , false , None ) ;
781
-
782
- self . with_new_scopes ( move |this| {
779
+ let ( body_id, generator_option) = self . with_new_scopes ( move |this| {
783
780
let prev = this. current_item ;
784
781
this. current_item = Some ( fn_decl_span) ;
785
782
let mut generator_kind = None ;
@@ -791,8 +788,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
791
788
let generator_option =
792
789
this. generator_movability_for_fn ( & decl, fn_decl_span, generator_kind, movability) ;
793
790
this. current_item = prev;
794
- hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, generator_option)
795
- } )
791
+ ( body_id, generator_option)
792
+ } ) ;
793
+
794
+ // Lower outside new scope to preserve `is_in_loop_condition`.
795
+ let fn_decl = self . lower_fn_decl ( decl, None , false , None ) ;
796
+
797
+ hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, generator_option)
796
798
}
797
799
798
800
fn generator_movability_for_fn (
@@ -838,12 +840,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
838
840
) -> hir:: ExprKind < ' hir > {
839
841
let outer_decl =
840
842
FnDecl { inputs : decl. inputs . clone ( ) , output : FnRetTy :: Default ( fn_decl_span) } ;
841
- // We need to lower the declaration outside the new scope, because we
842
- // have to conserve the state of being inside a loop condition for the
843
- // closure argument types.
844
- let fn_decl = self . lower_fn_decl ( & outer_decl, None , false , None ) ;
845
843
846
- self . with_new_scopes ( move |this| {
844
+ let body_id = self . with_new_scopes ( |this| {
847
845
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
848
846
if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
849
847
struct_span_err ! (
@@ -874,8 +872,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
874
872
) ;
875
873
this. expr ( fn_decl_span, async_body, ThinVec :: new ( ) )
876
874
} ) ;
877
- hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, None )
878
- } )
875
+ body_id
876
+ } ) ;
877
+
878
+ // We need to lower the declaration outside the new scope, because we
879
+ // have to conserve the state of being inside a loop condition for the
880
+ // closure argument types.
881
+ let fn_decl = self . lower_fn_decl ( & outer_decl, None , false , None ) ;
882
+
883
+ hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, None )
879
884
}
880
885
881
886
/// Destructure the LHS of complex assignments.
0 commit comments