@@ -9,7 +9,7 @@ use rustc_data_structures::thin_vec::ThinVec;
9
9
use rustc_errors:: struct_span_err;
10
10
use rustc_hir as hir;
11
11
use 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 } ;
13
13
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
14
14
use rustc_target:: asm;
15
15
use std:: collections:: hash_map:: Entry ;
@@ -25,6 +25,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
25
25
}
26
26
27
27
pub ( super ) fn lower_expr_mut ( & mut self , e : & Expr ) -> hir:: Expr < ' hir > {
28
+ let mut span = e. span ;
28
29
ensure_sufficient_stack ( || {
29
30
let kind = match e. kind {
30
31
ExprKind :: Box ( ref inner) => hir:: ExprKind :: Box ( self . lower_expr ( inner) ) ,
@@ -53,6 +54,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
53
54
hir:: ExprKind :: MethodCall ( hir_seg, seg. ident . span , args, span)
54
55
}
55
56
ExprKind :: Binary ( binop, ref lhs, ref rhs) => {
57
+ span = self . mark_span_with_reason ( DesugaringKind :: Operator , e. span , None ) ;
56
58
let binop = self . lower_binop ( binop) ;
57
59
let lhs = self . lower_expr ( lhs) ;
58
60
let rhs = self . lower_expr ( rhs) ;
@@ -222,7 +224,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
222
224
hir:: Expr {
223
225
hir_id : self . lower_node_id ( e. id ) ,
224
226
kind,
225
- span : e . span ,
227
+ span,
226
228
attrs : e. attrs . iter ( ) . map ( |a| self . lower_attr ( a) ) . collect :: < Vec < _ > > ( ) . into ( ) ,
227
229
}
228
230
} )
@@ -237,6 +239,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
237
239
}
238
240
239
241
fn lower_binop ( & mut self , b : BinOp ) -> hir:: BinOp {
242
+ let span = self . mark_span_with_reason ( DesugaringKind :: Operator , b. span , None ) ;
240
243
Spanned {
241
244
node : match b. node {
242
245
BinOpKind :: Add => hir:: BinOpKind :: Add ,
@@ -258,7 +261,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
258
261
BinOpKind :: Ge => hir:: BinOpKind :: Ge ,
259
262
BinOpKind :: Gt => hir:: BinOpKind :: Gt ,
260
263
} ,
261
- span : b . span ,
264
+ span,
262
265
}
263
266
}
264
267
@@ -1360,9 +1363,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
1360
1363
body : & Block ,
1361
1364
opt_label : Option < Label > ,
1362
1365
) -> hir:: Expr < ' hir > {
1366
+ let orig_head_span = head. span ;
1363
1367
// expand <head>
1364
1368
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
+ ) ;
1366
1374
head. span = desugared_span;
1367
1375
1368
1376
let iter = Ident :: with_dummy_span ( sym:: iter) ;
@@ -1457,10 +1465,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
1457
1465
// `mut iter => { ... }`
1458
1466
let iter_arm = self . arm ( iter_pat, loop_expr) ;
1459
1467
1468
+ let into_iter_span = self . mark_span_with_reason (
1469
+ DesugaringKind :: ForLoop ( ForLoopLoc :: IntoIter ) ,
1470
+ orig_head_span,
1471
+ None ,
1472
+ ) ;
1473
+
1460
1474
// `match ::std::iter::IntoIterator::into_iter(<head>) { ... }`
1461
1475
let into_iter_expr = {
1462
1476
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] )
1464
1478
} ;
1465
1479
1466
1480
let match_expr = self . arena . alloc ( self . expr_match (
0 commit comments