@@ -130,7 +130,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
130130 hir:: AsyncGeneratorKind :: Block ,
131131 |this| this. with_new_scopes ( |this| this. lower_block_expr ( block) ) ,
132132 ) ,
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+ }
134142 ExprKind :: Closure (
135143 capture_clause,
136144 asyncness,
@@ -479,8 +487,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
479487 expr : & ' hir hir:: Expr < ' hir > ,
480488 overall_span : Span ,
481489 ) -> & ' 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+ ) ) ;
484496 self . expr_call ( overall_span, constructor, std:: slice:: from_ref ( expr) )
485497 }
486498
@@ -584,8 +596,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
584596 // `future::from_generator`:
585597 let unstable_span =
586598 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+ ) ;
589605
590606 // `future::from_generator(generator)`:
591607 hir:: ExprKind :: Call ( self . arena . alloc ( gen_future) , arena_vec ! [ self ; generator] )
@@ -607,6 +623,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
607623 /// }
608624 /// ```
609625 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) ;
610627 match self . generator_kind {
611628 Some ( hir:: GeneratorKind :: Async ( _) ) => { }
612629 Some ( hir:: GeneratorKind :: Gen ) | None => {
@@ -623,13 +640,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
623640 err. emit ( ) ;
624641 }
625642 }
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 ) ;
627644 let gen_future_span = self . mark_span_with_reason (
628645 DesugaringKind :: Await ,
629646 await_span,
630647 self . allow_gen_future . clone ( ) ,
631648 ) ;
632649 let expr = self . lower_expr_mut ( expr) ;
650+ let expr_hir_id = expr. hir_id ;
633651
634652 let pinned_ident = Ident :: with_dummy_span ( sym:: pinned) ;
635653 let ( pinned_pat, pinned_pat_hid) =
@@ -656,16 +674,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
656674 span,
657675 hir:: LangItem :: PinNewUnchecked ,
658676 arena_vec ! [ self ; ref_mut_pinned] ,
677+ Some ( expr_hir_id) ,
659678 ) ;
660679 let get_context = self . expr_call_lang_item_fn_mut (
661680 gen_future_span,
662681 hir:: LangItem :: GetContext ,
663682 arena_vec ! [ self ; task_context] ,
683+ Some ( expr_hir_id) ,
664684 ) ;
665685 let call = self . expr_call_lang_item_fn (
666686 span,
667687 hir:: LangItem :: FuturePoll ,
668688 arena_vec ! [ self ; new_unchecked, get_context] ,
689+ Some ( expr_hir_id) ,
669690 ) ;
670691 self . arena . alloc ( self . expr_unsafe ( call) )
671692 } ;
@@ -678,18 +699,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
678699 let ( x_pat, x_pat_hid) = self . pat_ident ( span, x_ident) ;
679700 let x_expr = self . expr_ident ( span, x_ident, x_pat_hid) ;
680701 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+ ) ;
682708 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
683709 let expr_break =
684710 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 ( ) ) )
686712 } ) ;
687713 self . arm ( ready_pat, break_x)
688714 } ;
689715
690716 // `::std::task::Poll::Pending => {}`
691717 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+ ) ;
693724 let empty_block = self . expr_block_empty ( span) ;
694725 self . arm ( pending_pat, empty_block)
695726 } ;
@@ -709,7 +740,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
709740 let unit = self . expr_unit ( span) ;
710741 let yield_expr = self . expr (
711742 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 ) } ) ,
713744 ThinVec :: new ( ) ,
714745 ) ;
715746 let yield_expr = self . arena . alloc ( yield_expr) ;
@@ -756,6 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
756787 into_future_span,
757788 hir:: LangItem :: IntoFutureIntoFuture ,
758789 arena_vec ! [ self ; expr] ,
790+ Some ( expr_hir_id) ,
759791 ) ;
760792
761793 // match <into_future_expr> {
@@ -1160,7 +1192,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11601192 fn lower_expr_range_closed ( & mut self , span : Span , e1 : & Expr , e2 : & Expr ) -> hir:: ExprKind < ' hir > {
11611193 let e1 = self . lower_expr_mut ( e1) ;
11621194 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 ) ;
11641197 let fn_expr =
11651198 self . arena . alloc ( self . expr ( span, hir:: ExprKind :: Path ( fn_path) , ThinVec :: new ( ) ) ) ;
11661199 hir:: ExprKind :: Call ( fn_expr, arena_vec ! [ self ; e1, e2] )
@@ -1194,7 +1227,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11941227 ) ;
11951228
11961229 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 ) ) ,
11981231 fields,
11991232 None ,
12001233 )
@@ -1389,6 +1422,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13891422 head_span,
13901423 hir:: LangItem :: IteratorNext ,
13911424 arena_vec ! [ self ; ref_mut_iter] ,
1425+ None ,
13921426 ) ;
13931427 let arms = arena_vec ! [ self ; none_arm, some_arm] ;
13941428
@@ -1417,6 +1451,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14171451 head_span,
14181452 hir:: LangItem :: IntoIterIntoIter ,
14191453 arena_vec ! [ self ; head] ,
1454+ None ,
14201455 )
14211456 } ;
14221457
@@ -1472,6 +1507,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14721507 unstable_span,
14731508 hir:: LangItem :: TryTraitBranch ,
14741509 arena_vec ! [ self ; sub_expr] ,
1510+ None ,
14751511 )
14761512 } ;
14771513
@@ -1628,8 +1664,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
16281664 span : Span ,
16291665 lang_item : hir:: LangItem ,
16301666 args : & ' hir [ hir:: Expr < ' hir > ] ,
1667+ hir_id : Option < hir:: HirId > ,
16311668 ) -> 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) ) ;
16331671 self . expr_call_mut ( span, path, args)
16341672 }
16351673
@@ -1638,19 +1676,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
16381676 span : Span ,
16391677 lang_item : hir:: LangItem ,
16401678 args : & ' hir [ hir:: Expr < ' hir > ] ,
1679+ hir_id : Option < hir:: HirId > ,
16411680 ) -> & ' 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 ) )
16431682 }
16441683
16451684 fn expr_lang_item_path (
16461685 & mut self ,
16471686 span : Span ,
16481687 lang_item : hir:: LangItem ,
16491688 attrs : AttrVec ,
1689+ hir_id : Option < hir:: HirId > ,
16501690 ) -> hir:: Expr < ' hir > {
16511691 self . expr (
16521692 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 ) ) ,
16541694 attrs,
16551695 )
16561696 }
0 commit comments