@@ -632,17 +632,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
632632 // whereas a generator does not.
633633 let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
634634 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+
642653 let input_ty = hir:: Ty {
643654 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 ) ,
646657 } ;
647658 let inputs = arena_vec ! [ self ; input_ty] ;
648659
@@ -744,7 +755,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
744755 /// mut __awaitee => loop {
745756 /// match unsafe { ::std::future::Future::poll(
746757 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
747- /// ::std::future::get_context( task_context) ,
758+ /// task_context,
748759 /// ) } {
749760 /// ::std::task::Poll::Ready(result) => break result,
750761 /// ::std::task::Poll::Pending => {}
@@ -803,26 +814,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
803814 FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
804815 } ;
805816 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- ) ;
811817 let expr_hir_id = expr. hir_id ;
812818
813819 // Note that the name of this binding must not be changed to something else because
814820 // debuggers and debugger extensions expect it to be called `__awaitee`. They use
815821 // this name to identify what is being awaited by a suspended async functions.
816822 let awaitee_ident = Ident :: with_dummy_span ( sym:: __awaitee) ;
817823 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 ) ;
819825
820826 let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
821827
822828 // unsafe {
823829 // ::std::future::Future::poll(
824830 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
825- // ::std::future::get_context( task_context) ,
831+ // task_context,
826832 // )
827833 // }
828834 let poll_expr = {
@@ -840,21 +846,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
840846 hir:: LangItem :: PinNewUnchecked ,
841847 arena_vec ! [ self ; ref_mut_awaitee] ,
842848 ) ;
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- ) ;
848849 let call = match await_kind {
849850 FutureKind :: Future => self . expr_call_lang_item_fn (
850851 span,
851852 hir:: LangItem :: FuturePoll ,
852- arena_vec ! [ self ; new_unchecked, get_context ] ,
853+ arena_vec ! [ self ; new_unchecked, task_context ] ,
853854 ) ,
854855 FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
855856 span,
856857 hir:: LangItem :: AsyncIteratorPollNext ,
857- arena_vec ! [ self ; new_unchecked, get_context ] ,
858+ arena_vec ! [ self ; new_unchecked, task_context ] ,
858859 ) ,
859860 } ;
860861 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -865,14 +866,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
865866 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
866867 let ready_arm = {
867868 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) ;
871872 let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
872873 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
873874 let expr_break =
874875 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) )
876877 } ) ;
877878 self . arm ( ready_pat, break_x)
878879 } ;
0 commit comments