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