@@ -9,7 +9,7 @@ use rustc_data_structures::thin_vec::ThinVec;
99use rustc_errors:: struct_span_err;
1010use rustc_hir as hir;
1111use rustc_hir:: def:: Res ;
12- use rustc_span:: source_map:: { respan, DesugaringKind , Span , Spanned } ;
12+ use rustc_span:: source_map:: { respan, DesugaringKind , ForLoopLoc , Span , Spanned } ;
1313use rustc_span:: symbol:: { sym, Ident , Symbol } ;
1414use rustc_target:: asm;
1515use std:: collections:: hash_map:: Entry ;
@@ -25,6 +25,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
2525 }
2626
2727 pub ( super ) fn lower_expr_mut ( & mut self , e : & Expr ) -> hir:: Expr < ' hir > {
28+ let mut span = e. span ;
2829 ensure_sufficient_stack ( || {
2930 let kind = match e. kind {
3031 ExprKind :: Box ( ref inner) => hir:: ExprKind :: Box ( self . lower_expr ( inner) ) ,
@@ -53,6 +54,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
5354 hir:: ExprKind :: MethodCall ( hir_seg, seg. ident . span , args, span)
5455 }
5556 ExprKind :: Binary ( binop, ref lhs, ref rhs) => {
57+ span = self . mark_span_with_reason ( DesugaringKind :: Operator , e. span , None ) ;
5658 let binop = self . lower_binop ( binop) ;
5759 let lhs = self . lower_expr ( lhs) ;
5860 let rhs = self . lower_expr ( rhs) ;
@@ -222,7 +224,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
222224 hir:: Expr {
223225 hir_id : self . lower_node_id ( e. id ) ,
224226 kind,
225- span : e . span ,
227+ span,
226228 attrs : e. attrs . iter ( ) . map ( |a| self . lower_attr ( a) ) . collect :: < Vec < _ > > ( ) . into ( ) ,
227229 }
228230 } )
@@ -237,6 +239,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
237239 }
238240
239241 fn lower_binop ( & mut self , b : BinOp ) -> hir:: BinOp {
242+ let span = self . mark_span_with_reason ( DesugaringKind :: Operator , b. span , None ) ;
240243 Spanned {
241244 node : match b. node {
242245 BinOpKind :: Add => hir:: BinOpKind :: Add ,
@@ -258,7 +261,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
258261 BinOpKind :: Ge => hir:: BinOpKind :: Ge ,
259262 BinOpKind :: Gt => hir:: BinOpKind :: Gt ,
260263 } ,
261- span : b . span ,
264+ span,
262265 }
263266 }
264267
@@ -1360,9 +1363,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
13601363 body : & Block ,
13611364 opt_label : Option < Label > ,
13621365 ) -> hir:: Expr < ' hir > {
1366+ let orig_head_span = head. span ;
13631367 // expand <head>
13641368 let mut head = self . lower_expr_mut ( head) ;
1365- let desugared_span = self . mark_span_with_reason ( DesugaringKind :: ForLoop , head. span , None ) ;
1369+ let desugared_span = self . mark_span_with_reason (
1370+ DesugaringKind :: ForLoop ( ForLoopLoc :: Head ) ,
1371+ orig_head_span,
1372+ None ,
1373+ ) ;
13661374 head. span = desugared_span;
13671375
13681376 let iter = Ident :: with_dummy_span ( sym:: iter) ;
@@ -1457,10 +1465,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
14571465 // `mut iter => { ... }`
14581466 let iter_arm = self . arm ( iter_pat, loop_expr) ;
14591467
1468+ let into_iter_span = self . mark_span_with_reason (
1469+ DesugaringKind :: ForLoop ( ForLoopLoc :: IntoIter ) ,
1470+ orig_head_span,
1471+ None ,
1472+ ) ;
1473+
14601474 // `match ::std::iter::IntoIterator::into_iter(<head>) { ... }`
14611475 let into_iter_expr = {
14621476 let into_iter_path = & [ sym:: iter, sym:: IntoIterator , sym:: into_iter] ;
1463- self . expr_call_std_path ( desugared_span , into_iter_path, arena_vec ! [ self ; head] )
1477+ self . expr_call_std_path ( into_iter_span , into_iter_path, arena_vec ! [ self ; head] )
14641478 } ;
14651479
14661480 let match_expr = self . arena . alloc ( self . expr_match (
0 commit comments