@@ -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, ThinVec } ;
2222
@@ -603,14 +603,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
603603 ) -> hir:: ExprKind < ' hir > {
604604 let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
605605
606- // Resume argument type: `ResumeTy`
607- let unstable_span =
608- self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
609- let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span, None ) ;
606+ // Resume argument type: `&mut Context<'_>`.
607+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
608+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
609+ hir_id : self . next_id ( ) ,
610+ ident : context_lifetime_ident,
611+ res : hir:: LifetimeName :: Infer ,
612+ } ) ;
613+ let context_path =
614+ hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) , None ) ;
615+ let context_ty = hir:: MutTy {
616+ ty : self . arena . alloc ( hir:: Ty {
617+ hir_id : self . next_id ( ) ,
618+ kind : hir:: TyKind :: Path ( context_path) ,
619+ span : self . lower_span ( span) ,
620+ } ) ,
621+ mutbl : hir:: Mutability :: Mut ,
622+ } ;
623+
610624 let input_ty = hir:: Ty {
611625 hir_id : self . next_id ( ) ,
612- kind : hir:: TyKind :: Path ( resume_ty ) ,
613- span : unstable_span ,
626+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
627+ span : self . lower_span ( span ) ,
614628 } ;
615629
616630 // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -693,7 +707,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
693707 /// mut __awaitee => loop {
694708 /// match unsafe { ::std::future::Future::poll(
695709 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
696- /// ::std::future::get_context( task_context) ,
710+ /// task_context,
697711 /// ) } {
698712 /// ::std::task::Poll::Ready(result) => break result,
699713 /// ::std::task::Poll::Pending => {}
@@ -714,11 +728,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
714728 }
715729 }
716730 let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, None ) ;
717- let gen_future_span = self . mark_span_with_reason (
718- DesugaringKind :: Await ,
719- full_span,
720- self . allow_gen_future . clone ( ) ,
721- ) ;
722731 let expr = self . lower_expr_mut ( expr) ;
723732 let expr_hir_id = expr. hir_id ;
724733
@@ -734,7 +743,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
734743 // unsafe {
735744 // ::std::future::Future::poll(
736745 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
737- // ::std::future::get_context( task_context) ,
746+ // task_context,
738747 // )
739748 // }
740749 let poll_expr = {
@@ -752,16 +761,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
752761 arena_vec ! [ self ; ref_mut_awaitee] ,
753762 Some ( expr_hir_id) ,
754763 ) ;
755- let get_context = self . expr_call_lang_item_fn_mut (
756- gen_future_span,
757- hir:: LangItem :: GetContext ,
758- arena_vec ! [ self ; task_context] ,
759- Some ( expr_hir_id) ,
760- ) ;
761764 let call = self . expr_call_lang_item_fn (
762765 span,
763766 hir:: LangItem :: FuturePoll ,
764- arena_vec ! [ self ; new_unchecked, get_context ] ,
767+ arena_vec ! [ self ; new_unchecked, task_context ] ,
765768 Some ( expr_hir_id) ,
766769 ) ;
767770 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -772,9 +775,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
772775 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
773776 let ready_arm = {
774777 let x_ident = Ident :: with_dummy_span ( sym:: result) ;
775- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
776- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
777- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
778+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
779+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
780+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
778781 let ready_pat = self . pat_lang_item_variant (
779782 span,
780783 hir:: LangItem :: PollReady ,
@@ -784,7 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
784787 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
785788 let expr_break =
786789 hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
787- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
790+ this. arena . alloc ( this. expr ( full_span , expr_break) )
788791 } ) ;
789792 self . arm ( ready_pat, break_x)
790793 } ;
0 commit comments