@@ -615,17 +615,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
615615 // whereas a generator does not.
616616 let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
617617 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+
625636 let input_ty = hir:: Ty {
626637 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 ) ,
629640 } ;
630641 let inputs = arena_vec ! [ self ; input_ty] ;
631642
@@ -725,7 +736,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
725736 /// mut __awaitee => loop {
726737 /// match unsafe { ::std::future::Future::poll(
727738 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
728- /// ::std::future::get_context( task_context) ,
739+ /// task_context,
729740 /// ) } {
730741 /// ::std::task::Poll::Ready(result) => break result,
731742 /// ::std::task::Poll::Pending => {}
@@ -766,29 +777,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
766777 FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
767778 } ;
768779 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- ) ;
774780 let expr_hir_id = expr. hir_id ;
775781
776782 // Note that the name of this binding must not be changed to something else because
777783 // debuggers and debugger extensions expect it to be called `__awaitee`. They use
778784 // this name to identify what is being awaited by a suspended async functions.
779785 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 ) ;
785788
786789 let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
787790
788791 // unsafe {
789792 // ::std::future::Future::poll(
790793 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
791- // ::std::future::get_context( task_context) ,
794+ // task_context,
792795 // )
793796 // }
794797 let poll_expr = {
@@ -806,21 +809,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
806809 hir:: LangItem :: PinNewUnchecked ,
807810 arena_vec ! [ self ; ref_mut_awaitee] ,
808811 ) ;
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- ) ;
814812 let call = match await_kind {
815813 FutureKind :: Future => self . expr_call_lang_item_fn (
816814 span,
817815 hir:: LangItem :: FuturePoll ,
818- arena_vec ! [ self ; new_unchecked, get_context ] ,
816+ arena_vec ! [ self ; new_unchecked, task_context ] ,
819817 ) ,
820818 FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
821819 span,
822820 hir:: LangItem :: AsyncIteratorPollNext ,
823- arena_vec ! [ self ; new_unchecked, get_context ] ,
821+ arena_vec ! [ self ; new_unchecked, task_context ] ,
824822 ) ,
825823 } ;
826824 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -831,14 +829,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
831829 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
832830 let ready_arm = {
833831 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) ;
837835 let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
838836 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
839837 let expr_break =
840838 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) )
842840 } ) ;
843841 self . arm ( ready_pat, break_x)
844842 } ;
0 commit comments