@@ -632,17 +632,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
632
632
// whereas a generator does not.
633
633
let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
634
634
hir:: CoroutineDesugaring :: Async | hir:: CoroutineDesugaring :: AsyncGen => {
635
- // Resume argument type: `ResumeTy`
636
- let unstable_span = self . mark_span_with_reason (
637
- DesugaringKind :: Async ,
638
- self . lower_span ( span) ,
639
- Some ( self . allow_gen_future . clone ( ) ) ,
640
- ) ;
641
- let resume_ty = self . make_lang_item_qpath ( hir:: LangItem :: ResumeTy , unstable_span) ;
635
+ // Resume argument type: `&mut Context<'_>`.
636
+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
637
+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
638
+ hir_id : self . next_id ( ) ,
639
+ ident : context_lifetime_ident,
640
+ res : hir:: LifetimeName :: Infer ,
641
+ } ) ;
642
+ let context_path =
643
+ hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) ) ;
644
+ let context_ty = hir:: MutTy {
645
+ ty : self . arena . alloc ( hir:: Ty {
646
+ hir_id : self . next_id ( ) ,
647
+ kind : hir:: TyKind :: Path ( context_path) ,
648
+ span : self . lower_span ( span) ,
649
+ } ) ,
650
+ mutbl : hir:: Mutability :: Mut ,
651
+ } ;
652
+
642
653
let input_ty = hir:: Ty {
643
654
hir_id : self . next_id ( ) ,
644
- kind : hir:: TyKind :: Path ( resume_ty ) ,
645
- span : unstable_span ,
655
+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
656
+ span : self . lower_span ( span ) ,
646
657
} ;
647
658
let inputs = arena_vec ! [ self ; input_ty] ;
648
659
@@ -744,7 +755,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
744
755
/// mut __awaitee => loop {
745
756
/// match unsafe { ::std::future::Future::poll(
746
757
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
747
- /// ::std::future::get_context( task_context) ,
758
+ /// task_context,
748
759
/// ) } {
749
760
/// ::std::task::Poll::Ready(result) => break result,
750
761
/// ::std::task::Poll::Pending => {}
@@ -803,26 +814,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
803
814
FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
804
815
} ;
805
816
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, features) ;
806
- let gen_future_span = self . mark_span_with_reason (
807
- DesugaringKind :: Await ,
808
- full_span,
809
- Some ( self . allow_gen_future . clone ( ) ) ,
810
- ) ;
811
817
let expr_hir_id = expr. hir_id ;
812
818
813
819
// Note that the name of this binding must not be changed to something else because
814
820
// debuggers and debugger extensions expect it to be called `__awaitee`. They use
815
821
// this name to identify what is being awaited by a suspended async functions.
816
822
let awaitee_ident = Ident :: with_dummy_span ( sym:: __awaitee) ;
817
823
let ( awaitee_pat, awaitee_pat_hid) =
818
- self . pat_ident_binding_mode ( gen_future_span , awaitee_ident, hir:: BindingMode :: MUT ) ;
824
+ self . pat_ident_binding_mode ( full_span , awaitee_ident, hir:: BindingMode :: MUT ) ;
819
825
820
826
let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
821
827
822
828
// unsafe {
823
829
// ::std::future::Future::poll(
824
830
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
825
- // ::std::future::get_context( task_context) ,
831
+ // task_context,
826
832
// )
827
833
// }
828
834
let poll_expr = {
@@ -840,21 +846,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
840
846
hir:: LangItem :: PinNewUnchecked ,
841
847
arena_vec ! [ self ; ref_mut_awaitee] ,
842
848
) ;
843
- let get_context = self . expr_call_lang_item_fn_mut (
844
- gen_future_span,
845
- hir:: LangItem :: GetContext ,
846
- arena_vec ! [ self ; task_context] ,
847
- ) ;
848
849
let call = match await_kind {
849
850
FutureKind :: Future => self . expr_call_lang_item_fn (
850
851
span,
851
852
hir:: LangItem :: FuturePoll ,
852
- arena_vec ! [ self ; new_unchecked, get_context ] ,
853
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
853
854
) ,
854
855
FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
855
856
span,
856
857
hir:: LangItem :: AsyncIteratorPollNext ,
857
- arena_vec ! [ self ; new_unchecked, get_context ] ,
858
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
858
859
) ,
859
860
} ;
860
861
self . arena . alloc ( self . expr_unsafe ( call) )
@@ -865,14 +866,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
865
866
let loop_hir_id = self . lower_node_id ( loop_node_id) ;
866
867
let ready_arm = {
867
868
let x_ident = Ident :: with_dummy_span ( sym:: result) ;
868
- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
869
- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
870
- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
869
+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
870
+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
871
+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
871
872
let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
872
873
let break_x = self . with_loop_scope ( loop_node_id, move |this| {
873
874
let expr_break =
874
875
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
875
- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
876
+ this. arena . alloc ( this. expr ( full_span , expr_break) )
876
877
} ) ;
877
878
self . arm ( ready_pat, break_x)
878
879
} ;
0 commit comments