@@ -10,9 +10,9 @@ use rustc_errors::struct_span_err;
10
10
use rustc_hir as hir;
11
11
use rustc_hir:: def:: Res ;
12
12
use rustc_session:: parse:: feature_err;
13
+ use rustc_span:: hygiene:: ForLoopLoc ;
13
14
use rustc_span:: source_map:: { respan, DesugaringKind , Span , Spanned } ;
14
15
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
15
- use rustc_span:: { hygiene:: ForLoopLoc , DUMMY_SP } ;
16
16
use rustc_target:: asm;
17
17
use std:: collections:: hash_map:: Entry ;
18
18
use std:: fmt:: Write ;
@@ -102,7 +102,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
102
102
this. lower_block ( body, false ) ,
103
103
opt_label,
104
104
hir:: LoopSource :: Loop ,
105
- DUMMY_SP ,
106
105
)
107
106
} ) ,
108
107
ExprKind :: TryBlock ( ref body) => self . lower_expr_try_block ( body) ,
@@ -454,12 +453,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
454
453
self . expr_match ( span, scrutinee, arena_vec ! [ self ; then_arm, else_arm] , desugar) ;
455
454
456
455
// `[opt_ident]: loop { ... }`
457
- hir:: ExprKind :: Loop (
458
- self . block_expr ( self . arena . alloc ( match_expr) ) ,
459
- opt_label,
460
- source,
461
- span. with_hi ( cond. span . hi ( ) ) ,
462
- )
456
+ hir:: ExprKind :: Loop ( self . block_expr ( self . arena . alloc ( match_expr) ) , opt_label, source)
463
457
}
464
458
465
459
/// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok(<expr>) }`,
@@ -754,7 +748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
754
748
// loop { .. }
755
749
let loop_expr = self . arena . alloc ( hir:: Expr {
756
750
hir_id : loop_hir_id,
757
- kind : hir:: ExprKind :: Loop ( loop_block, None , hir:: LoopSource :: Loop , span ) ,
751
+ kind : hir:: ExprKind :: Loop ( loop_block, None , hir:: LoopSource :: Loop ) ,
758
752
span,
759
753
attrs : ThinVec :: new ( ) ,
760
754
} ) ;
@@ -776,7 +770,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
776
770
body : & Expr ,
777
771
fn_decl_span : Span ,
778
772
) -> hir:: ExprKind < ' hir > {
779
- let ( body_id, generator_option) = self . with_new_scopes ( move |this| {
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| {
780
777
let prev = this. current_item ;
781
778
this. current_item = Some ( fn_decl_span) ;
782
779
let mut generator_kind = None ;
@@ -788,13 +785,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
788
785
let generator_option =
789
786
this. generator_movability_for_fn ( & decl, fn_decl_span, generator_kind, movability) ;
790
787
this. current_item = prev;
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)
788
+ hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, generator_option)
789
+ } )
798
790
}
799
791
800
792
fn generator_movability_for_fn (
@@ -840,8 +832,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
840
832
) -> hir:: ExprKind < ' hir > {
841
833
let outer_decl =
842
834
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 ) ;
843
839
844
- let body_id = self . with_new_scopes ( |this| {
840
+ self . with_new_scopes ( move |this| {
845
841
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
846
842
if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
847
843
struct_span_err ! (
@@ -872,15 +868,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
872
868
) ;
873
869
this. expr ( fn_decl_span, async_body, ThinVec :: new ( ) )
874
870
} ) ;
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 )
871
+ hir:: ExprKind :: Closure ( capture_clause, fn_decl, body_id, fn_decl_span, None )
872
+ } )
884
873
}
885
874
886
875
/// Destructure the LHS of complex assignments.
@@ -1720,12 +1709,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1720
1709
) ;
1721
1710
1722
1711
// `[opt_ident]: loop { ... }`
1723
- let kind = hir:: ExprKind :: Loop (
1724
- loop_block,
1725
- opt_label,
1726
- hir:: LoopSource :: ForLoop ,
1727
- e. span . with_hi ( orig_head_span. hi ( ) ) ,
1728
- ) ;
1712
+ let kind = hir:: ExprKind :: Loop ( loop_block, opt_label, hir:: LoopSource :: ForLoop ) ;
1729
1713
let loop_expr = self . arena . alloc ( hir:: Expr {
1730
1714
hir_id : self . lower_node_id ( e. id ) ,
1731
1715
kind,
0 commit comments