@@ -30,6 +30,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
30
30
31
31
pub ( super ) fn lower_expr_mut ( & mut self , e : & Expr ) -> hir:: Expr < ' hir > {
32
32
ensure_sufficient_stack ( || {
33
+ let mut span = None ;
33
34
let kind = match e. kind {
34
35
ExprKind :: Box ( ref inner) => hir:: ExprKind :: Box ( self . lower_expr ( inner) ) ,
35
36
ExprKind :: Array ( ref exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
@@ -210,10 +211,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
210
211
hir:: ExprKind :: Index ( self . lower_expr ( el) , self . lower_expr ( er) )
211
212
}
212
213
ExprKind :: Range ( Some ( ref e1) , Some ( ref e2) , RangeLimits :: Closed ) => {
213
- self . lower_expr_range_closed ( e. span , e1, e2)
214
+ let ( kind, s) = self . lower_expr_range_closed ( e. span , e1, e2) ;
215
+ span = Some ( s) ;
216
+ kind
214
217
}
215
218
ExprKind :: Range ( ref e1, ref e2, lims) => {
216
- self . lower_expr_range ( e. span , e1. as_deref ( ) , e2. as_deref ( ) , lims)
219
+ let ( kind, s) =
220
+ self . lower_expr_range ( e. span , e1. as_deref ( ) , e2. as_deref ( ) , lims) ;
221
+ span = Some ( s) ;
222
+ kind
217
223
}
218
224
ExprKind :: Underscore => {
219
225
self . tcx . sess . emit_err ( UnderscoreExprLhsAssign { span : e. span } ) ;
@@ -303,7 +309,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
303
309
304
310
let hir_id = self . lower_node_id ( e. id ) ;
305
311
self . lower_attrs ( hir_id, & e. attrs ) ;
306
- hir:: Expr { hir_id, kind, span : self . lower_span ( e. span ) }
312
+ let span = span. unwrap_or_else ( || self . lower_span ( e. span ) ) ;
313
+ hir:: Expr { hir_id, kind, span }
307
314
} )
308
315
}
309
316
@@ -529,12 +536,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
529
536
expr : & ' hir hir:: Expr < ' hir > ,
530
537
overall_span : Span ,
531
538
) -> & ' hir hir:: Expr < ' hir > {
532
- let constructor = self . arena . alloc ( self . expr_lang_item_path (
533
- method_span,
534
- lang_item,
535
- AttrVec :: new ( ) ,
536
- None ,
537
- ) ) ;
539
+ let constructor = self . expr_lang_item_path ( method_span, lang_item) ;
538
540
self . expr_call ( overall_span, constructor, std:: slice:: from_ref ( expr) )
539
541
}
540
542
@@ -652,15 +654,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
652
654
// `future::from_generator`:
653
655
let unstable_span =
654
656
self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
655
- let gen_future = self . expr_lang_item_path (
656
- unstable_span,
657
- hir:: LangItem :: FromGenerator ,
658
- AttrVec :: new ( ) ,
659
- None ,
660
- ) ;
657
+ let gen_future = self . expr_lang_item_path ( unstable_span, hir:: LangItem :: FromGenerator ) ;
661
658
662
659
// `future::from_generator(generator)`:
663
- hir:: ExprKind :: Call ( self . arena . alloc ( gen_future) , arena_vec ! [ self ; generator] )
660
+ hir:: ExprKind :: Call ( gen_future, arena_vec ! [ self ; generator] )
664
661
}
665
662
666
663
/// Desugar `<expr>.await` into:
@@ -726,19 +723,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
726
723
span,
727
724
hir:: LangItem :: PinNewUnchecked ,
728
725
arena_vec ! [ self ; ref_mut_awaitee] ,
729
- Some ( expr_hir_id) ,
730
726
) ;
731
727
let get_context = self . expr_call_lang_item_fn_mut (
732
728
gen_future_span,
733
729
hir:: LangItem :: GetContext ,
734
730
arena_vec ! [ self ; task_context] ,
735
- Some ( expr_hir_id) ,
736
731
) ;
737
732
let call = self . expr_call_lang_item_fn (
738
733
span,
739
734
hir:: LangItem :: FuturePoll ,
740
735
arena_vec ! [ self ; new_unchecked, get_context] ,
741
- Some ( expr_hir_id) ,
742
736
) ;
743
737
self . arena . alloc ( self . expr_unsafe ( call) )
744
738
} ;
@@ -751,12 +745,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
751
745
let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span, x_ident) ;
752
746
let x_expr = self . expr_ident ( gen_future_span, x_ident, x_pat_hid) ;
753
747
let ready_field = self . single_pat_field ( gen_future_span, x_pat) ;
754
- let ready_pat = self . pat_lang_item_variant (
755
- span,
756
- hir:: LangItem :: PollReady ,
757
- ready_field,
758
- Some ( expr_hir_id) ,
759
- ) ;
748
+ let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
760
749
let break_x = self . with_loop_scope ( loop_node_id, move |this| {
761
750
let expr_break =
762
751
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
@@ -767,12 +756,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
767
756
768
757
// `::std::task::Poll::Pending => {}`
769
758
let pending_arm = {
770
- let pending_pat = self . pat_lang_item_variant (
771
- span,
772
- hir:: LangItem :: PollPending ,
773
- & [ ] ,
774
- Some ( expr_hir_id) ,
775
- ) ;
759
+ let pending_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollPending , & [ ] ) ;
776
760
let empty_block = self . expr_block_empty ( span) ;
777
761
self . arm ( pending_pat, empty_block)
778
762
} ;
@@ -839,7 +823,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
839
823
into_future_span,
840
824
hir:: LangItem :: IntoFutureIntoFuture ,
841
825
arena_vec ! [ self ; expr] ,
842
- Some ( expr_hir_id) ,
843
826
) ;
844
827
845
828
// match <into_future_expr> {
@@ -1269,14 +1252,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
1269
1252
}
1270
1253
1271
1254
/// Desugar `<start>..=<end>` into `std::ops::RangeInclusive::new(<start>, <end>)`.
1272
- fn lower_expr_range_closed ( & mut self , span : Span , e1 : & Expr , e2 : & Expr ) -> hir:: ExprKind < ' hir > {
1255
+ fn lower_expr_range_closed (
1256
+ & mut self ,
1257
+ span : Span ,
1258
+ e1 : & Expr ,
1259
+ e2 : & Expr ,
1260
+ ) -> ( hir:: ExprKind < ' hir > , Span ) {
1273
1261
let e1 = self . lower_expr_mut ( e1) ;
1274
1262
let e2 = self . lower_expr_mut ( e2) ;
1275
- let fn_path =
1276
- hir :: QPath :: LangItem ( hir :: LangItem :: RangeInclusiveNew , self . lower_span ( span) , None ) ;
1277
- let fn_expr =
1278
- self . arena . alloc ( self . expr ( span , hir:: ExprKind :: Path ( fn_path ) , AttrVec :: new ( ) ) ) ;
1279
- hir :: ExprKind :: Call ( fn_expr , arena_vec ! [ self ; e1 , e2 ] )
1263
+ let span =
1264
+ self . mark_span_with_reason ( DesugaringKind :: RangeLiteral , self . lower_span ( span) , None ) ;
1265
+ let fn_expr = self . expr_lang_item_path ( span , hir :: LangItem :: RangeInclusiveNew ) ;
1266
+ let kind = hir:: ExprKind :: Call ( fn_expr , arena_vec ! [ self ; e1 , e2 ] ) ;
1267
+ ( kind , span )
1280
1268
}
1281
1269
1282
1270
fn lower_expr_range (
@@ -1285,7 +1273,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1285
1273
e1 : Option < & Expr > ,
1286
1274
e2 : Option < & Expr > ,
1287
1275
lims : RangeLimits ,
1288
- ) -> hir:: ExprKind < ' hir > {
1276
+ ) -> ( hir:: ExprKind < ' hir > , Span ) {
1289
1277
use rustc_ast:: RangeLimits :: * ;
1290
1278
1291
1279
let lang_item = match ( e1, e2, lims) {
@@ -1308,17 +1296,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
1308
1296
e1. iter ( ) . map ( |e| ( sym:: start, e) ) . chain ( e2. iter ( ) . map ( |e| ( sym:: end, e) ) ) . map (
1309
1297
|( s, e) | {
1310
1298
let expr = self . lower_expr ( & e) ;
1311
- let ident = Ident :: new ( s, self . lower_span ( e. span ) ) ;
1299
+ let ident_span =
1300
+ self . mark_span_with_reason ( DesugaringKind :: RangeLiteral , expr. span , None ) ;
1301
+ let ident = Ident :: new ( s, ident_span) ;
1312
1302
self . expr_field ( ident, expr, e. span )
1313
1303
} ,
1314
1304
) ,
1315
1305
) ;
1316
1306
1317
- hir:: ExprKind :: Struct (
1318
- self . arena . alloc ( hir:: QPath :: LangItem ( lang_item, self . lower_span ( span) , None ) ) ,
1319
- fields,
1320
- None ,
1321
- )
1307
+ let span =
1308
+ self . mark_span_with_reason ( DesugaringKind :: RangeLiteral , self . lower_span ( span) , None ) ;
1309
+ let qpath = self . lang_item_qpath ( lang_item, span) ;
1310
+ ( hir:: ExprKind :: Struct ( self . arena . alloc ( qpath) , fields, None ) , span)
1322
1311
}
1323
1312
1324
1313
fn lower_label ( & self , opt_label : Option < Label > ) -> Option < Label > {
@@ -1474,7 +1463,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1474
1463
head_span,
1475
1464
hir:: LangItem :: IteratorNext ,
1476
1465
arena_vec ! [ self ; ref_mut_iter] ,
1477
- None ,
1478
1466
) ;
1479
1467
let arms = arena_vec ! [ self ; none_arm, some_arm] ;
1480
1468
@@ -1503,7 +1491,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1503
1491
head_span,
1504
1492
hir:: LangItem :: IntoIterIntoIter ,
1505
1493
arena_vec ! [ self ; head] ,
1506
- None ,
1507
1494
)
1508
1495
} ;
1509
1496
@@ -1557,7 +1544,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1557
1544
unstable_span,
1558
1545
hir:: LangItem :: TryTraitBranch ,
1559
1546
arena_vec ! [ self ; sub_expr] ,
1560
- None ,
1561
1547
)
1562
1548
} ;
1563
1549
@@ -1751,10 +1737,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1751
1737
span : Span ,
1752
1738
lang_item : hir:: LangItem ,
1753
1739
args : & ' hir [ hir:: Expr < ' hir > ] ,
1754
- hir_id : Option < hir:: HirId > ,
1755
1740
) -> hir:: Expr < ' hir > {
1756
- let path =
1757
- self . arena . alloc ( self . expr_lang_item_path ( span, lang_item, AttrVec :: new ( ) , hir_id) ) ;
1741
+ let path = self . arena . alloc ( self . expr_lang_item_path ( span, lang_item) ) ;
1758
1742
self . expr_call_mut ( span, path, args)
1759
1743
}
1760
1744
@@ -1763,23 +1747,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
1763
1747
span : Span ,
1764
1748
lang_item : hir:: LangItem ,
1765
1749
args : & ' hir [ hir:: Expr < ' hir > ] ,
1766
- hir_id : Option < hir:: HirId > ,
1767
1750
) -> & ' hir hir:: Expr < ' hir > {
1768
- self . arena . alloc ( self . expr_call_lang_item_fn_mut ( span, lang_item, args, hir_id ) )
1751
+ self . arena . alloc ( self . expr_call_lang_item_fn_mut ( span, lang_item, args) )
1769
1752
}
1770
1753
1771
1754
fn expr_lang_item_path (
1772
1755
& mut self ,
1773
1756
span : Span ,
1774
1757
lang_item : hir:: LangItem ,
1775
- attrs : AttrVec ,
1776
- hir_id : Option < hir:: HirId > ,
1777
- ) -> hir:: Expr < ' hir > {
1778
- self . expr (
1779
- span,
1780
- hir:: ExprKind :: Path ( hir:: QPath :: LangItem ( lang_item, self . lower_span ( span) , hir_id) ) ,
1781
- attrs,
1782
- )
1758
+ ) -> & ' hir hir:: Expr < ' hir > {
1759
+ let qpath = self . lang_item_qpath ( lang_item, span) ;
1760
+ let kind = hir:: ExprKind :: Path ( qpath) ;
1761
+ self . arena . alloc ( self . expr ( span, kind, AttrVec :: new ( ) ) )
1783
1762
}
1784
1763
1785
1764
pub ( super ) fn expr_ident (
0 commit comments