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