@@ -621,17 +621,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
621
621
// whereas a generator does not.
622
622
let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
623
623
hir:: CoroutineDesugaring :: Async | hir:: CoroutineDesugaring :: AsyncGen => {
624
- // Resume argument type: `ResumeTy`
625
- let unstable_span = self . mark_span_with_reason (
626
- DesugaringKind :: Async ,
627
- self . lower_span ( span) ,
628
- Some ( self . allow_gen_future . clone ( ) ) ,
629
- ) ;
630
- let resume_ty = self . make_lang_item_qpath ( hir:: LangItem :: ResumeTy , unstable_span) ;
624
+ // Resume argument type: `&mut Context<'_>`.
625
+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
626
+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
627
+ hir_id : self . next_id ( ) ,
628
+ ident : context_lifetime_ident,
629
+ res : hir:: LifetimeName :: Infer ,
630
+ } ) ;
631
+ let context_path =
632
+ hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) ) ;
633
+ let context_ty = hir:: MutTy {
634
+ ty : self . arena . alloc ( hir:: Ty {
635
+ hir_id : self . next_id ( ) ,
636
+ kind : hir:: TyKind :: Path ( context_path) ,
637
+ span : self . lower_span ( span) ,
638
+ } ) ,
639
+ mutbl : hir:: Mutability :: Mut ,
640
+ } ;
641
+
631
642
let input_ty = hir:: Ty {
632
643
hir_id : self . next_id ( ) ,
633
- kind : hir:: TyKind :: Path ( resume_ty ) ,
634
- span : unstable_span ,
644
+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
645
+ span : self . lower_span ( span ) ,
635
646
} ;
636
647
let inputs = arena_vec ! [ self ; input_ty] ;
637
648
@@ -731,7 +742,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
731
742
/// mut __awaitee => loop {
732
743
/// match unsafe { ::std::future::Future::poll(
733
744
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
734
- /// ::std::future::get_context( task_context) ,
745
+ /// task_context,
735
746
/// ) } {
736
747
/// ::std::task::Poll::Ready(result) => break result,
737
748
/// ::std::task::Poll::Pending => {}
@@ -772,29 +783,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
772
783
FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
773
784
} ;
774
785
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, features) ;
775
- let gen_future_span = self . mark_span_with_reason (
776
- DesugaringKind :: Await ,
777
- full_span,
778
- Some ( self . allow_gen_future . clone ( ) ) ,
779
- ) ;
780
786
let expr_hir_id = expr. hir_id ;
781
787
782
788
// Note that the name of this binding must not be changed to something else because
783
789
// debuggers and debugger extensions expect it to be called `__awaitee`. They use
784
790
// this name to identify what is being awaited by a suspended async functions.
785
791
let awaitee_ident = Ident :: with_dummy_span ( sym:: __awaitee) ;
786
- let ( awaitee_pat, awaitee_pat_hid) = self . pat_ident_binding_mode (
787
- gen_future_span,
788
- awaitee_ident,
789
- hir:: BindingAnnotation :: MUT ,
790
- ) ;
792
+ let ( awaitee_pat, awaitee_pat_hid) =
793
+ self . pat_ident_binding_mode ( full_span, awaitee_ident, hir:: BindingAnnotation :: MUT ) ;
791
794
792
795
let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
793
796
794
797
// unsafe {
795
798
// ::std::future::Future::poll(
796
799
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
797
- // ::std::future::get_context( task_context) ,
800
+ // task_context,
798
801
// )
799
802
// }
800
803
let poll_expr = {
@@ -812,21 +815,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
812
815
hir:: LangItem :: PinNewUnchecked ,
813
816
arena_vec ! [ self ; ref_mut_awaitee] ,
814
817
) ;
815
- let get_context = self . expr_call_lang_item_fn_mut (
816
- gen_future_span,
817
- hir:: LangItem :: GetContext ,
818
- arena_vec ! [ self ; task_context] ,
819
- ) ;
820
818
let call = match await_kind {
821
819
FutureKind :: Future => self . expr_call_lang_item_fn (
822
820
span,
823
821
hir:: LangItem :: FuturePoll ,
824
- arena_vec ! [ self ; new_unchecked, get_context ] ,
822
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
825
823
) ,
826
824
FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
827
825
span,
828
826
hir:: LangItem :: AsyncIteratorPollNext ,
829
- arena_vec ! [ self ; new_unchecked, get_context ] ,
827
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
830
828
) ,
831
829
} ;
832
830
self . arena . alloc ( self . expr_unsafe ( call) )
@@ -837,14 +835,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
837
835
let loop_hir_id = self . lower_node_id ( loop_node_id) ;
838
836
let ready_arm = {
839
837
let x_ident = Ident :: with_dummy_span ( sym:: result) ;
840
- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
841
- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
842
- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
838
+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
839
+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
840
+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
843
841
let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
844
842
let break_x = self . with_loop_scope ( loop_node_id, move |this| {
845
843
let expr_break =
846
844
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
847
- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
845
+ this. arena . alloc ( this. expr ( full_span , expr_break) )
848
846
} ) ;
849
847
self . arm ( ready_pat, break_x)
850
848
} ;
0 commit comments