@@ -252,11 +252,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
252252 ExprKind :: Err => hir:: ExprKind :: Err ,
253253 ExprKind :: Try ( ref sub_expr) => self . lower_expr_try ( e. span , sub_expr) ,
254254 ExprKind :: Paren ( ref ex) => {
255- let mut ex = self . lower_expr_mut ( ex) ;
255+ let ex = self . lower_expr_mut ( ex) ;
256256 // 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 ;
260260 }
261261 // Merge attributes into the inner expression.
262262 if !e. attrs . is_empty ( ) {
@@ -284,7 +284,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
284284
285285 let hir_id = self . lower_node_id ( e. id , e. span ) ;
286286 self . lower_attrs ( hir_id, & e. attrs ) ;
287- hir:: Expr { hir_id, kind, span : e . span }
287+ hir:: Expr { hir_id, kind }
288288 } )
289289 }
290290
@@ -535,8 +535,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
535535
536536 // Lower condition:
537537 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+ ) ;
540543 // Wrap in a construct equivalent to `{ let _t = $cond; _t }`
541544 // to preserve drop semantics since `while cond { ... }` does not
542545 // let temporaries live outside of `cond`.
@@ -574,7 +577,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
574577 (
575578 this. mark_span_with_reason (
576579 DesugaringKind :: TryBlock ,
577- expr. span ,
580+ this . spans [ expr. hir_id ] ,
578581 this. allow_try_trait . clone ( ) ,
579582 ) ,
580583 expr,
@@ -589,8 +592,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
589592 ( try_span, this. expr_unit ( try_span) )
590593 } ;
591594
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+ ) ;
594600
595601 // `::std::ops::Try::from_ok($tail_expr)`
596602 block. expr = Some ( this. wrap_in_try_constructor (
@@ -692,11 +698,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
692698 span,
693699 Some ( hir:: Movability :: Static ) ,
694700 ) ;
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 } ;
700703
701704 // `future::from_generator`:
702705 let unstable_span =
@@ -849,7 +852,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
849852 let loop_expr = self . arena . alloc ( hir:: Expr {
850853 hir_id : loop_hir_id,
851854 kind : hir:: ExprKind :: Loop ( loop_block, None , hir:: LoopSource :: Loop , span) ,
852- span,
853855 } ) ;
854856
855857 // mut pinned => loop { ... }
@@ -1720,13 +1722,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
17201722 ) -> hir:: Expr < ' hir > {
17211723 let orig_head_span = head. span ;
17221724 // expand <head>
1723- let mut head = self . lower_expr_mut ( head) ;
1725+ let head = self . lower_expr_mut ( head) ;
17241726 let desugared_span = self . mark_span_with_reason (
17251727 DesugaringKind :: ForLoop ( ForLoopLoc :: Head ) ,
17261728 orig_head_span,
17271729 None ,
17281730 ) ;
1729- head. span = desugared_span;
17301731 self . spans [ head. hir_id ] = desugared_span;
17311732
17321733 let iter = Ident :: with_dummy_span ( sym:: iter) ;
@@ -1818,11 +1819,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
18181819 hir:: LoopSource :: ForLoop ,
18191820 e. span . with_hi ( orig_head_span. hi ( ) ) ,
18201821 ) ;
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 } ) ;
18261824
18271825 // `mut iter => { ... }`
18281826 let iter_arm = self . arm ( iter_pat, loop_expr) ;
@@ -2118,7 +2116,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21182116 }
21192117
21202118 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 ] ;
21222120 let hir_id = self . next_id ( span) ;
21232121 self . expr (
21242122 span,
@@ -2159,14 +2157,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
21592157 ) -> hir:: Expr < ' hir > {
21602158 let hir_id = self . next_id ( span) ;
21612159 self . lower_attrs ( hir_id, & attrs) ;
2162- hir:: Expr { hir_id, kind, span }
2160+ hir:: Expr { hir_id, kind }
21632161 }
21642162
21652163 fn field ( & mut self , ident : Ident , expr : & ' hir hir:: Expr < ' hir > , span : Span ) -> hir:: Field < ' hir > {
21662164 hir:: Field { hir_id : self . next_id ( span) , ident, expr, is_shorthand : false }
21672165 }
21682166
21692167 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 }
21712170 }
21722171}
0 commit comments