@@ -130,7 +130,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
130
130
hir:: AsyncGeneratorKind :: Block ,
131
131
|this| this. with_new_scopes ( |this| this. lower_block_expr ( block) ) ,
132
132
) ,
133
- ExprKind :: Await ( ref expr) => self . lower_expr_await ( e. span , expr) ,
133
+ ExprKind :: Await ( ref expr) => {
134
+ let span = if expr. span . hi ( ) < e. span . hi ( ) {
135
+ expr. span . shrink_to_hi ( ) . with_hi ( e. span . hi ( ) )
136
+ } else {
137
+ // this is a recovered `await expr`
138
+ e. span
139
+ } ;
140
+ self . lower_expr_await ( span, expr)
141
+ }
134
142
ExprKind :: Closure (
135
143
capture_clause,
136
144
asyncness,
@@ -479,8 +487,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
479
487
expr : & ' hir hir:: Expr < ' hir > ,
480
488
overall_span : Span ,
481
489
) -> & ' hir hir:: Expr < ' hir > {
482
- let constructor =
483
- self . arena . alloc ( self . expr_lang_item_path ( method_span, lang_item, ThinVec :: new ( ) ) ) ;
490
+ let constructor = self . arena . alloc ( self . expr_lang_item_path (
491
+ method_span,
492
+ lang_item,
493
+ ThinVec :: new ( ) ,
494
+ None ,
495
+ ) ) ;
484
496
self . expr_call ( overall_span, constructor, std:: slice:: from_ref ( expr) )
485
497
}
486
498
@@ -584,8 +596,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
584
596
// `future::from_generator`:
585
597
let unstable_span =
586
598
self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
587
- let gen_future =
588
- self . expr_lang_item_path ( unstable_span, hir:: LangItem :: FromGenerator , ThinVec :: new ( ) ) ;
599
+ let gen_future = self . expr_lang_item_path (
600
+ unstable_span,
601
+ hir:: LangItem :: FromGenerator ,
602
+ ThinVec :: new ( ) ,
603
+ None ,
604
+ ) ;
589
605
590
606
// `future::from_generator(generator)`:
591
607
hir:: ExprKind :: Call ( self . arena . alloc ( gen_future) , arena_vec ! [ self ; generator] )
@@ -607,6 +623,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
607
623
/// }
608
624
/// ```
609
625
fn lower_expr_await ( & mut self , await_span : Span , expr : & Expr ) -> hir:: ExprKind < ' hir > {
626
+ let dot_await_span = expr. span . shrink_to_hi ( ) . to ( await_span) ;
610
627
match self . generator_kind {
611
628
Some ( hir:: GeneratorKind :: Async ( _) ) => { }
612
629
Some ( hir:: GeneratorKind :: Gen ) | None => {
@@ -623,13 +640,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
623
640
err. emit ( ) ;
624
641
}
625
642
}
626
- let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_span , None ) ;
643
+ let span = self . mark_span_with_reason ( DesugaringKind :: Await , dot_await_span , None ) ;
627
644
let gen_future_span = self . mark_span_with_reason (
628
645
DesugaringKind :: Await ,
629
646
await_span,
630
647
self . allow_gen_future . clone ( ) ,
631
648
) ;
632
649
let expr = self . lower_expr_mut ( expr) ;
650
+ let expr_hir_id = expr. hir_id ;
633
651
634
652
let pinned_ident = Ident :: with_dummy_span ( sym:: pinned) ;
635
653
let ( pinned_pat, pinned_pat_hid) =
@@ -656,16 +674,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
656
674
span,
657
675
hir:: LangItem :: PinNewUnchecked ,
658
676
arena_vec ! [ self ; ref_mut_pinned] ,
677
+ Some ( expr_hir_id) ,
659
678
) ;
660
679
let get_context = self . expr_call_lang_item_fn_mut (
661
680
gen_future_span,
662
681
hir:: LangItem :: GetContext ,
663
682
arena_vec ! [ self ; task_context] ,
683
+ Some ( expr_hir_id) ,
664
684
) ;
665
685
let call = self . expr_call_lang_item_fn (
666
686
span,
667
687
hir:: LangItem :: FuturePoll ,
668
688
arena_vec ! [ self ; new_unchecked, get_context] ,
689
+ Some ( expr_hir_id) ,
669
690
) ;
670
691
self . arena . alloc ( self . expr_unsafe ( call) )
671
692
} ;
@@ -678,18 +699,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
678
699
let ( x_pat, x_pat_hid) = self . pat_ident ( span, x_ident) ;
679
700
let x_expr = self . expr_ident ( span, x_ident, x_pat_hid) ;
680
701
let ready_field = self . single_pat_field ( span, x_pat) ;
681
- let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
702
+ let ready_pat = self . pat_lang_item_variant (
703
+ span,
704
+ hir:: LangItem :: PollReady ,
705
+ ready_field,
706
+ Some ( expr_hir_id) ,
707
+ ) ;
682
708
let break_x = self . with_loop_scope ( loop_node_id, move |this| {
683
709
let expr_break =
684
710
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
685
- this. arena . alloc ( this. expr ( await_span , expr_break, ThinVec :: new ( ) ) )
711
+ this. arena . alloc ( this. expr ( span , expr_break, ThinVec :: new ( ) ) )
686
712
} ) ;
687
713
self . arm ( ready_pat, break_x)
688
714
} ;
689
715
690
716
// `::std::task::Poll::Pending => {}`
691
717
let pending_arm = {
692
- let pending_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollPending , & [ ] ) ;
718
+ let pending_pat = self . pat_lang_item_variant (
719
+ span,
720
+ hir:: LangItem :: PollPending ,
721
+ & [ ] ,
722
+ Some ( expr_hir_id) ,
723
+ ) ;
693
724
let empty_block = self . expr_block_empty ( span) ;
694
725
self . arm ( pending_pat, empty_block)
695
726
} ;
@@ -709,7 +740,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
709
740
let unit = self . expr_unit ( span) ;
710
741
let yield_expr = self . expr (
711
742
span,
712
- hir:: ExprKind :: Yield ( unit, hir:: YieldSource :: Await { expr : Some ( expr . hir_id ) } ) ,
743
+ hir:: ExprKind :: Yield ( unit, hir:: YieldSource :: Await { expr : Some ( expr_hir_id ) } ) ,
713
744
ThinVec :: new ( ) ,
714
745
) ;
715
746
let yield_expr = self . arena . alloc ( yield_expr) ;
@@ -756,6 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
756
787
into_future_span,
757
788
hir:: LangItem :: IntoFutureIntoFuture ,
758
789
arena_vec ! [ self ; expr] ,
790
+ Some ( expr_hir_id) ,
759
791
) ;
760
792
761
793
// match <into_future_expr> {
@@ -1160,7 +1192,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1160
1192
fn lower_expr_range_closed ( & mut self , span : Span , e1 : & Expr , e2 : & Expr ) -> hir:: ExprKind < ' hir > {
1161
1193
let e1 = self . lower_expr_mut ( e1) ;
1162
1194
let e2 = self . lower_expr_mut ( e2) ;
1163
- let fn_path = hir:: QPath :: LangItem ( hir:: LangItem :: RangeInclusiveNew , self . lower_span ( span) ) ;
1195
+ let fn_path =
1196
+ hir:: QPath :: LangItem ( hir:: LangItem :: RangeInclusiveNew , self . lower_span ( span) , None ) ;
1164
1197
let fn_expr =
1165
1198
self . arena . alloc ( self . expr ( span, hir:: ExprKind :: Path ( fn_path) , ThinVec :: new ( ) ) ) ;
1166
1199
hir:: ExprKind :: Call ( fn_expr, arena_vec ! [ self ; e1, e2] )
@@ -1194,7 +1227,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1194
1227
) ;
1195
1228
1196
1229
hir:: ExprKind :: Struct (
1197
- self . arena . alloc ( hir:: QPath :: LangItem ( lang_item, self . lower_span ( span) ) ) ,
1230
+ self . arena . alloc ( hir:: QPath :: LangItem ( lang_item, self . lower_span ( span) , None ) ) ,
1198
1231
fields,
1199
1232
None ,
1200
1233
)
@@ -1389,6 +1422,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1389
1422
head_span,
1390
1423
hir:: LangItem :: IteratorNext ,
1391
1424
arena_vec ! [ self ; ref_mut_iter] ,
1425
+ None ,
1392
1426
) ;
1393
1427
let arms = arena_vec ! [ self ; none_arm, some_arm] ;
1394
1428
@@ -1417,6 +1451,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1417
1451
head_span,
1418
1452
hir:: LangItem :: IntoIterIntoIter ,
1419
1453
arena_vec ! [ self ; head] ,
1454
+ None ,
1420
1455
)
1421
1456
} ;
1422
1457
@@ -1472,6 +1507,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1472
1507
unstable_span,
1473
1508
hir:: LangItem :: TryTraitBranch ,
1474
1509
arena_vec ! [ self ; sub_expr] ,
1510
+ None ,
1475
1511
)
1476
1512
} ;
1477
1513
@@ -1628,8 +1664,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
1628
1664
span : Span ,
1629
1665
lang_item : hir:: LangItem ,
1630
1666
args : & ' hir [ hir:: Expr < ' hir > ] ,
1667
+ hir_id : Option < hir:: HirId > ,
1631
1668
) -> hir:: Expr < ' hir > {
1632
- let path = self . arena . alloc ( self . expr_lang_item_path ( span, lang_item, ThinVec :: new ( ) ) ) ;
1669
+ let path =
1670
+ self . arena . alloc ( self . expr_lang_item_path ( span, lang_item, ThinVec :: new ( ) , hir_id) ) ;
1633
1671
self . expr_call_mut ( span, path, args)
1634
1672
}
1635
1673
@@ -1638,19 +1676,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
1638
1676
span : Span ,
1639
1677
lang_item : hir:: LangItem ,
1640
1678
args : & ' hir [ hir:: Expr < ' hir > ] ,
1679
+ hir_id : Option < hir:: HirId > ,
1641
1680
) -> & ' hir hir:: Expr < ' hir > {
1642
- self . arena . alloc ( self . expr_call_lang_item_fn_mut ( span, lang_item, args) )
1681
+ self . arena . alloc ( self . expr_call_lang_item_fn_mut ( span, lang_item, args, hir_id ) )
1643
1682
}
1644
1683
1645
1684
fn expr_lang_item_path (
1646
1685
& mut self ,
1647
1686
span : Span ,
1648
1687
lang_item : hir:: LangItem ,
1649
1688
attrs : AttrVec ,
1689
+ hir_id : Option < hir:: HirId > ,
1650
1690
) -> hir:: Expr < ' hir > {
1651
1691
self . expr (
1652
1692
span,
1653
- hir:: ExprKind :: Path ( hir:: QPath :: LangItem ( lang_item, self . lower_span ( span) ) ) ,
1693
+ hir:: ExprKind :: Path ( hir:: QPath :: LangItem ( lang_item, self . lower_span ( span) , hir_id ) ) ,
1654
1694
attrs,
1655
1695
)
1656
1696
}
0 commit comments