@@ -252,11 +252,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
252
252
ExprKind :: Err => hir:: ExprKind :: Err ,
253
253
ExprKind :: Try ( ref sub_expr) => self . lower_expr_try ( e. span , sub_expr) ,
254
254
ExprKind :: Paren ( ref ex) => {
255
- let mut ex = self . lower_expr_mut ( ex) ;
255
+ let ex = self . lower_expr_mut ( ex) ;
256
256
// Include parens in span, but only if it is a super-span.
257
- if e . span . contains ( ex. span ) {
258
- ex . span = e. span ;
259
- self . spans [ ex . hir_id ] = e. span ;
257
+ let ex_span = & mut self . spans [ ex. hir_id ] ;
258
+ if e. span . contains ( * ex_span ) {
259
+ * ex_span = e. span ;
260
260
}
261
261
// Merge attributes into the inner expression.
262
262
if !e. attrs . is_empty ( ) {
@@ -284,7 +284,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
284
284
285
285
let hir_id = self . lower_node_id ( e. id , e. span ) ;
286
286
self . lower_attrs ( hir_id, & e. attrs ) ;
287
- hir:: Expr { hir_id, kind, span : e . span }
287
+ hir:: Expr { hir_id, kind }
288
288
} )
289
289
}
290
290
@@ -535,8 +535,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
535
535
536
536
// Lower condition:
537
537
let cond = self . with_loop_condition_scope ( |this| this. lower_expr ( cond) ) ;
538
- let span_block =
539
- self . mark_span_with_reason ( DesugaringKind :: CondTemporary , cond. span , None ) ;
538
+ let span_block = self . mark_span_with_reason (
539
+ DesugaringKind :: CondTemporary ,
540
+ self . spans [ cond. hir_id ] ,
541
+ None ,
542
+ ) ;
540
543
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
541
544
// to preserve drop semantics since `while cond { ... }` does not
542
545
// let temporaries live outside of `cond`.
@@ -574,7 +577,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
574
577
(
575
578
this. mark_span_with_reason (
576
579
DesugaringKind :: TryBlock ,
577
- expr. span ,
580
+ this . spans [ expr. hir_id ] ,
578
581
this. allow_try_trait . clone ( ) ,
579
582
) ,
580
583
expr,
@@ -589,8 +592,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
589
592
( try_span, this. expr_unit ( try_span) )
590
593
} ;
591
594
592
- let ok_wrapped_span =
593
- this. mark_span_with_reason ( DesugaringKind :: TryBlock , tail_expr. span , None ) ;
595
+ let ok_wrapped_span = this. mark_span_with_reason (
596
+ DesugaringKind :: TryBlock ,
597
+ this. spans [ tail_expr. hir_id ] ,
598
+ None ,
599
+ ) ;
594
600
595
601
// `::std::ops::Try::from_ok($tail_expr)`
596
602
block. expr = Some ( this. wrap_in_try_constructor (
@@ -692,11 +698,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
692
698
span,
693
699
Some ( hir:: Movability :: Static ) ,
694
700
) ;
695
- let generator = hir:: Expr {
696
- hir_id : self . lower_node_id ( closure_node_id, span) ,
697
- kind : generator_kind,
698
- span,
699
- } ;
701
+ let generator =
702
+ hir:: Expr { hir_id : self . lower_node_id ( closure_node_id, span) , kind : generator_kind } ;
700
703
701
704
// `future::from_generator`:
702
705
let unstable_span =
@@ -849,7 +852,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
849
852
let loop_expr = self . arena . alloc ( hir:: Expr {
850
853
hir_id : loop_hir_id,
851
854
kind : hir:: ExprKind :: Loop ( loop_block, None , hir:: LoopSource :: Loop , span) ,
852
- span,
853
855
} ) ;
854
856
855
857
// mut pinned => loop { ... }
@@ -1720,13 +1722,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
1720
1722
) -> hir:: Expr < ' hir > {
1721
1723
let orig_head_span = head. span ;
1722
1724
// expand <head>
1723
- let mut head = self . lower_expr_mut ( head) ;
1725
+ let head = self . lower_expr_mut ( head) ;
1724
1726
let desugared_span = self . mark_span_with_reason (
1725
1727
DesugaringKind :: ForLoop ( ForLoopLoc :: Head ) ,
1726
1728
orig_head_span,
1727
1729
None ,
1728
1730
) ;
1729
- head. span = desugared_span;
1730
1731
self . spans [ head. hir_id ] = desugared_span;
1731
1732
1732
1733
let iter = Ident :: with_dummy_span ( sym:: iter) ;
@@ -1818,11 +1819,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1818
1819
hir:: LoopSource :: ForLoop ,
1819
1820
e. span . with_hi ( orig_head_span. hi ( ) ) ,
1820
1821
) ;
1821
- let loop_expr = self . arena . alloc ( hir:: Expr {
1822
- hir_id : self . lower_node_id ( e. id , e. span ) ,
1823
- kind,
1824
- span : e. span ,
1825
- } ) ;
1822
+ let loop_expr =
1823
+ self . arena . alloc ( hir:: Expr { hir_id : self . lower_node_id ( e. id , e. span ) , kind } ) ;
1826
1824
1827
1825
// `mut iter => { ... }`
1828
1826
let iter_arm = self . arm ( iter_pat, loop_expr) ;
@@ -2118,7 +2116,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
2118
2116
}
2119
2117
2120
2118
fn expr_unsafe ( & mut self , expr : & ' hir hir:: Expr < ' hir > ) -> hir:: Expr < ' hir > {
2121
- let span = expr. span ;
2119
+ let span = self . spans [ expr. hir_id ] ;
2122
2120
let hir_id = self . next_id ( span) ;
2123
2121
self . expr (
2124
2122
span,
@@ -2159,14 +2157,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
2159
2157
) -> hir:: Expr < ' hir > {
2160
2158
let hir_id = self . next_id ( span) ;
2161
2159
self . lower_attrs ( hir_id, & attrs) ;
2162
- hir:: Expr { hir_id, kind, span }
2160
+ hir:: Expr { hir_id, kind }
2163
2161
}
2164
2162
2165
2163
fn field ( & mut self , ident : Ident , expr : & ' hir hir:: Expr < ' hir > , span : Span ) -> hir:: Field < ' hir > {
2166
2164
hir:: Field { hir_id : self . next_id ( span) , ident, expr, is_shorthand : false }
2167
2165
}
2168
2166
2169
2167
fn arm ( & mut self , pat : & ' hir hir:: Pat < ' hir > , expr : & ' hir hir:: Expr < ' hir > ) -> hir:: Arm < ' hir > {
2170
- hir:: Arm { hir_id : self . next_id ( expr. span ) , pat, guard : None , body : expr }
2168
+ let span = self . spans [ expr. hir_id ] ;
2169
+ hir:: Arm { hir_id : self . next_id ( span) , pat, guard : None , body : expr }
2171
2170
}
2172
2171
}
0 commit comments