@@ -621,17 +621,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
621621 // whereas a generator does not.
622622 let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
623623 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+
631642 let input_ty = hir:: Ty {
632643 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 ) ,
635646 } ;
636647 let inputs = arena_vec ! [ self ; input_ty] ;
637648
@@ -731,7 +742,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
731742 /// mut __awaitee => loop {
732743 /// match unsafe { ::std::future::Future::poll(
733744 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
734- /// ::std::future::get_context( task_context) ,
745+ /// task_context,
735746 /// ) } {
736747 /// ::std::task::Poll::Ready(result) => break result,
737748 /// ::std::task::Poll::Pending => {}
@@ -772,29 +783,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
772783 FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
773784 } ;
774785 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- ) ;
780786 let expr_hir_id = expr. hir_id ;
781787
782788 // Note that the name of this binding must not be changed to something else because
783789 // debuggers and debugger extensions expect it to be called `__awaitee`. They use
784790 // this name to identify what is being awaited by a suspended async functions.
785791 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 ) ;
791794
792795 let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
793796
794797 // unsafe {
795798 // ::std::future::Future::poll(
796799 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
797- // ::std::future::get_context( task_context) ,
800+ // task_context,
798801 // )
799802 // }
800803 let poll_expr = {
@@ -812,21 +815,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
812815 hir:: LangItem :: PinNewUnchecked ,
813816 arena_vec ! [ self ; ref_mut_awaitee] ,
814817 ) ;
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- ) ;
820818 let call = match await_kind {
821819 FutureKind :: Future => self . expr_call_lang_item_fn (
822820 span,
823821 hir:: LangItem :: FuturePoll ,
824- arena_vec ! [ self ; new_unchecked, get_context ] ,
822+ arena_vec ! [ self ; new_unchecked, task_context ] ,
825823 ) ,
826824 FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
827825 span,
828826 hir:: LangItem :: AsyncIteratorPollNext ,
829- arena_vec ! [ self ; new_unchecked, get_context ] ,
827+ arena_vec ! [ self ; new_unchecked, task_context ] ,
830828 ) ,
831829 } ;
832830 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -837,14 +835,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
837835 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
838836 let ready_arm = {
839837 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) ;
843841 let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
844842 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
845843 let expr_break =
846844 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) )
848846 } ) ;
849847 self . arm ( ready_pat, break_x)
850848 } ;
0 commit comments