@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
1616use rustc_hir:: definitions:: DefPathData ;
1717use rustc_session:: errors:: report_lit_error;
1818use rustc_span:: source_map:: { respan, DesugaringKind , Span , Spanned } ;
19- use rustc_span:: symbol:: { sym, Ident , Symbol } ;
19+ use rustc_span:: symbol:: { kw , sym, Ident , Symbol } ;
2020use rustc_span:: DUMMY_SP ;
2121use thin_vec:: thin_vec;
2222
@@ -599,14 +599,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
599599 ) -> hir:: ExprKind < ' hir > {
600600 let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
601601
602- // Resume argument type: `ResumeTy`
603- let unstable_span =
604- self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
605- let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span, None ) ;
602+ // Resume argument type: `&mut Context<'_>`.
603+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
604+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
605+ hir_id : self . next_id ( ) ,
606+ ident : context_lifetime_ident,
607+ res : hir:: LifetimeName :: Infer ,
608+ } ) ;
609+ let context_path =
610+ hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) , None ) ;
611+ let context_ty = hir:: MutTy {
612+ ty : self . arena . alloc ( hir:: Ty {
613+ hir_id : self . next_id ( ) ,
614+ kind : hir:: TyKind :: Path ( context_path) ,
615+ span : self . lower_span ( span) ,
616+ } ) ,
617+ mutbl : hir:: Mutability :: Mut ,
618+ } ;
619+
606620 let input_ty = hir:: Ty {
607621 hir_id : self . next_id ( ) ,
608- kind : hir:: TyKind :: Path ( resume_ty ) ,
609- span : unstable_span ,
622+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
623+ span : self . lower_span ( span ) ,
610624 } ;
611625
612626 // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -710,7 +724,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
710724 /// mut __awaitee => loop {
711725 /// match unsafe { ::std::future::Future::poll(
712726 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
713- /// ::std::future::get_context( task_context) ,
727+ /// task_context,
714728 /// ) } {
715729 /// ::std::task::Poll::Ready(result) => break result,
716730 /// ::std::task::Poll::Pending => {}
@@ -731,11 +745,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
731745 }
732746 }
733747 let span = self . mark_span_with_reason ( DesugaringKind :: Await , dot_await_span, None ) ;
734- let gen_future_span = self . mark_span_with_reason (
735- DesugaringKind :: Await ,
736- full_span,
737- self . allow_gen_future . clone ( ) ,
738- ) ;
739748 let expr = self . lower_expr_mut ( expr) ;
740749 let expr_hir_id = expr. hir_id ;
741750
@@ -751,7 +760,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
751760 // unsafe {
752761 // ::std::future::Future::poll(
753762 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
754- // ::std::future::get_context( task_context) ,
763+ // task_context,
755764 // )
756765 // }
757766 let poll_expr = {
@@ -769,16 +778,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
769778 arena_vec ! [ self ; ref_mut_awaitee] ,
770779 Some ( expr_hir_id) ,
771780 ) ;
772- let get_context = self . expr_call_lang_item_fn_mut (
773- gen_future_span,
774- hir:: LangItem :: GetContext ,
775- arena_vec ! [ self ; task_context] ,
776- Some ( expr_hir_id) ,
777- ) ;
778781 let call = self . expr_call_lang_item_fn (
779782 span,
780783 hir:: LangItem :: FuturePoll ,
781- arena_vec ! [ self ; new_unchecked, get_context ] ,
784+ arena_vec ! [ self ; new_unchecked, task_context ] ,
782785 Some ( expr_hir_id) ,
783786 ) ;
784787 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -789,9 +792,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
789792 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
790793 let ready_arm = {
791794 let x_ident = Ident :: with_dummy_span ( sym:: result) ;
792- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
793- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
794- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
795+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
796+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
797+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
795798 let ready_pat = self . pat_lang_item_variant (
796799 span,
797800 hir:: LangItem :: PollReady ,
@@ -801,7 +804,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
801804 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
802805 let expr_break =
803806 hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
804- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
807+ this. arena . alloc ( this. expr ( full_span , expr_break) )
805808 } ) ;
806809 self . arm ( ready_pat, break_x)
807810 } ;
0 commit comments