@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
16
16
use rustc_hir:: definitions:: DefPathData ;
17
17
use rustc_session:: errors:: report_lit_error;
18
18
use rustc_span:: source_map:: { respan, DesugaringKind , Span , Spanned } ;
19
- use rustc_span:: symbol:: { sym, Ident , Symbol } ;
19
+ use rustc_span:: symbol:: { kw , sym, Ident , Symbol } ;
20
20
use rustc_span:: DUMMY_SP ;
21
21
use thin_vec:: { thin_vec, ThinVec } ;
22
22
@@ -603,14 +603,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
603
603
) -> hir:: ExprKind < ' hir > {
604
604
let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
605
605
606
- // Resume argument type: `ResumeTy`
607
- let unstable_span =
608
- self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
609
- let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span, None ) ;
606
+ // Resume argument type: `&mut Context<'_>`.
607
+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
608
+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
609
+ hir_id : self . next_id ( ) ,
610
+ ident : context_lifetime_ident,
611
+ res : hir:: LifetimeName :: Infer ,
612
+ } ) ;
613
+ let context_path =
614
+ hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) , None ) ;
615
+ let context_ty = hir:: MutTy {
616
+ ty : self . arena . alloc ( hir:: Ty {
617
+ hir_id : self . next_id ( ) ,
618
+ kind : hir:: TyKind :: Path ( context_path) ,
619
+ span : self . lower_span ( span) ,
620
+ } ) ,
621
+ mutbl : hir:: Mutability :: Mut ,
622
+ } ;
623
+
610
624
let input_ty = hir:: Ty {
611
625
hir_id : self . next_id ( ) ,
612
- kind : hir:: TyKind :: Path ( resume_ty ) ,
613
- span : unstable_span ,
626
+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
627
+ span : self . lower_span ( span ) ,
614
628
} ;
615
629
616
630
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -693,7 +707,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
693
707
/// mut __awaitee => loop {
694
708
/// match unsafe { ::std::future::Future::poll(
695
709
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
696
- /// ::std::future::get_context( task_context) ,
710
+ /// task_context,
697
711
/// ) } {
698
712
/// ::std::task::Poll::Ready(result) => break result,
699
713
/// ::std::task::Poll::Pending => {}
@@ -714,11 +728,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
714
728
}
715
729
}
716
730
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, None ) ;
717
- let gen_future_span = self . mark_span_with_reason (
718
- DesugaringKind :: Await ,
719
- full_span,
720
- self . allow_gen_future . clone ( ) ,
721
- ) ;
722
731
let expr = self . lower_expr_mut ( expr) ;
723
732
let expr_hir_id = expr. hir_id ;
724
733
@@ -734,7 +743,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
734
743
// unsafe {
735
744
// ::std::future::Future::poll(
736
745
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
737
- // ::std::future::get_context( task_context) ,
746
+ // task_context,
738
747
// )
739
748
// }
740
749
let poll_expr = {
@@ -752,16 +761,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
752
761
arena_vec ! [ self ; ref_mut_awaitee] ,
753
762
Some ( expr_hir_id) ,
754
763
) ;
755
- let get_context = self . expr_call_lang_item_fn_mut (
756
- gen_future_span,
757
- hir:: LangItem :: GetContext ,
758
- arena_vec ! [ self ; task_context] ,
759
- Some ( expr_hir_id) ,
760
- ) ;
761
764
let call = self . expr_call_lang_item_fn (
762
765
span,
763
766
hir:: LangItem :: FuturePoll ,
764
- arena_vec ! [ self ; new_unchecked, get_context ] ,
767
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
765
768
Some ( expr_hir_id) ,
766
769
) ;
767
770
self . arena . alloc ( self . expr_unsafe ( call) )
@@ -772,9 +775,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
772
775
let loop_hir_id = self . lower_node_id ( loop_node_id) ;
773
776
let ready_arm = {
774
777
let x_ident = Ident :: with_dummy_span ( sym:: result) ;
775
- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
776
- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
777
- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
778
+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
779
+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
780
+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
778
781
let ready_pat = self . pat_lang_item_variant (
779
782
span,
780
783
hir:: LangItem :: PollReady ,
@@ -784,7 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
784
787
let break_x = self . with_loop_scope ( loop_node_id, move |this| {
785
788
let expr_break =
786
789
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
787
- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
790
+ this. arena . alloc ( this. expr ( full_span , expr_break) )
788
791
} ) ;
789
792
self . arm ( ready_pat, break_x)
790
793
} ;
0 commit comments