@@ -627,17 +627,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
627627 // whereas a generator does not.
628628 let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
629629 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+
637648 let input_ty = hir:: Ty {
638649 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 ) ,
641652 } ;
642653 let inputs = arena_vec ! [ self ; input_ty] ;
643654
@@ -737,7 +748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
737748 /// mut __awaitee => loop {
738749 /// match unsafe { ::std::future::Future::poll(
739750 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
740- /// ::std::future::get_context( task_context) ,
751+ /// task_context,
741752 /// ) } {
742753 /// ::std::task::Poll::Ready(result) => break result,
743754 /// ::std::task::Poll::Pending => {}
@@ -796,26 +807,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
796807 FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
797808 } ;
798809 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- ) ;
804810 let expr_hir_id = expr. hir_id ;
805811
806812 // Note that the name of this binding must not be changed to something else because
807813 // debuggers and debugger extensions expect it to be called `__awaitee`. They use
808814 // this name to identify what is being awaited by a suspended async functions.
809815 let awaitee_ident = Ident :: with_dummy_span ( sym:: __awaitee) ;
810816 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 ) ;
812818
813819 let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
814820
815821 // unsafe {
816822 // ::std::future::Future::poll(
817823 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
818- // ::std::future::get_context( task_context) ,
824+ // task_context,
819825 // )
820826 // }
821827 let poll_expr = {
@@ -833,21 +839,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
833839 hir:: LangItem :: PinNewUnchecked ,
834840 arena_vec ! [ self ; ref_mut_awaitee] ,
835841 ) ;
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- ) ;
841842 let call = match await_kind {
842843 FutureKind :: Future => self . expr_call_lang_item_fn (
843844 span,
844845 hir:: LangItem :: FuturePoll ,
845- arena_vec ! [ self ; new_unchecked, get_context ] ,
846+ arena_vec ! [ self ; new_unchecked, task_context ] ,
846847 ) ,
847848 FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
848849 span,
849850 hir:: LangItem :: AsyncIteratorPollNext ,
850- arena_vec ! [ self ; new_unchecked, get_context ] ,
851+ arena_vec ! [ self ; new_unchecked, task_context ] ,
851852 ) ,
852853 } ;
853854 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -858,14 +859,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
858859 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
859860 let ready_arm = {
860861 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) ;
864865 let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
865866 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
866867 let expr_break =
867868 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) )
869870 } ) ;
870871 self . arm ( ready_pat, break_x)
871872 } ;
0 commit comments