@@ -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:: { kw , sym, Ident } ;
19+ use rustc_span:: symbol:: { sym, Ident } ;
2020use rustc_span:: DUMMY_SP ;
2121use thin_vec:: thin_vec;
2222
@@ -585,38 +585,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
585585 ) -> hir:: ExprKind < ' hir > {
586586 let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
587587
588- // Resume argument type, which should be `&mut Context<'_>`.
589- // NOTE: Using the `'static` lifetime here is technically cheating.
590- // The `Future::poll` argument really is `&'a mut Context<'b>`, but we cannot
591- // express the fact that we are not storing it across yield-points yet,
592- // and we would thus run into lifetime errors.
593- // See <https://github.com/rust-lang/rust/issues/68923>.
594- // Our lowering makes sure we are not mis-using the `_task_context` input type
595- // in the sense that we are indeed not using it across yield points. We
596- // get a fresh `&mut Context` for each resume / call of `Future::poll`.
597- // This "cheating" was previously done with a `ResumeTy` that contained a raw
598- // pointer, and a `get_context` accessor that pulled the `Context` lifetimes
599- // out of thin air.
600- let context_lifetime_ident = Ident :: with_dummy_span ( kw:: StaticLifetime ) ;
601- let context_lifetime = self . arena . alloc ( hir:: Lifetime {
602- hir_id : self . next_id ( ) ,
603- ident : context_lifetime_ident,
604- res : hir:: LifetimeName :: Static ,
605- } ) ;
606- let context_path =
607- hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) , None ) ;
608- let context_ty = hir:: MutTy {
609- ty : self . arena . alloc ( hir:: Ty {
610- hir_id : self . next_id ( ) ,
611- kind : hir:: TyKind :: Path ( context_path) ,
612- span : self . lower_span ( span) ,
613- } ) ,
614- mutbl : hir:: Mutability :: Mut ,
615- } ;
588+ // Resume argument type: `ResumeTy`
589+ let unstable_span =
590+ self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
591+ let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span, None ) ;
616592 let input_ty = hir:: Ty {
617593 hir_id : self . next_id ( ) ,
618- kind : hir:: TyKind :: Rptr ( context_lifetime , context_ty ) ,
619- span : self . lower_span ( span ) ,
594+ kind : hir:: TyKind :: Path ( resume_ty ) ,
595+ span : unstable_span ,
620596 } ;
621597
622598 // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -674,9 +650,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
674650 . map_or ( false , |attrs| attrs. into_iter ( ) . any ( |attr| attr. has_name ( sym:: track_caller) ) ) ;
675651
676652 let hir_id = self . lower_node_id ( closure_node_id) ;
677- let unstable_span =
678- self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
679653 if track_caller {
654+ let unstable_span = self . mark_span_with_reason (
655+ DesugaringKind :: Async ,
656+ span,
657+ self . allow_gen_future . clone ( ) ,
658+ ) ;
680659 self . lower_attrs (
681660 hir_id,
682661 & [ Attribute {
@@ -719,7 +698,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
719698 /// mut __awaitee => loop {
720699 /// match unsafe { ::std::future::Future::poll(
721700 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
722- /// task_context,
701+ /// ::std::future::get_context( task_context) ,
723702 /// ) } {
724703 /// ::std::task::Poll::Ready(result) => break result,
725704 /// ::std::task::Poll::Pending => {}
@@ -760,7 +739,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
760739 // unsafe {
761740 // ::std::future::Future::poll(
762741 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
763- // task_context,
742+ // ::std::future::get_context( task_context) ,
764743 // )
765744 // }
766745 let poll_expr = {
@@ -778,10 +757,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
778757 arena_vec ! [ self ; ref_mut_awaitee] ,
779758 Some ( expr_hir_id) ,
780759 ) ;
760+ let get_context = self . expr_call_lang_item_fn_mut (
761+ gen_future_span,
762+ hir:: LangItem :: GetContext ,
763+ arena_vec ! [ self ; task_context] ,
764+ Some ( expr_hir_id) ,
765+ ) ;
781766 let call = self . expr_call_lang_item_fn (
782767 span,
783768 hir:: LangItem :: FuturePoll ,
784- arena_vec ! [ self ; new_unchecked, task_context ] ,
769+ arena_vec ! [ self ; new_unchecked, get_context ] ,
785770 Some ( expr_hir_id) ,
786771 ) ;
787772 self . arena . alloc ( self . expr_unsafe ( call) )
0 commit comments