@@ -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
@@ -596,38 +596,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
596596 ) -> hir:: ExprKind < ' hir > {
597597 let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
598598
599- // Resume argument type, which should be `&mut Context<'_>`.
600- // NOTE: Using the `'static` lifetime here is technically cheating.
601- // The `Future::poll` argument really is `&'a mut Context<'b>`, but we cannot
602- // express the fact that we are not storing it across yield-points yet,
603- // and we would thus run into lifetime errors.
604- // See <https://github.com/rust-lang/rust/issues/68923>.
605- // Our lowering makes sure we are not mis-using the `_task_context` input type
606- // in the sense that we are indeed not using it across yield points. We
607- // get a fresh `&mut Context` for each resume / call of `Future::poll`.
608- // This "cheating" was previously done with a `ResumeTy` that contained a raw
609- // pointer, and a `get_context` accessor that pulled the `Context` lifetimes
610- // out of thin air.
611- let context_lifetime_ident = Ident :: with_dummy_span ( kw:: StaticLifetime ) ;
612- let context_lifetime = self . arena . alloc ( hir:: Lifetime {
613- hir_id : self . next_id ( ) ,
614- ident : context_lifetime_ident,
615- res : hir:: LifetimeName :: Static ,
616- } ) ;
617- let context_path =
618- hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) , None ) ;
619- let context_ty = hir:: MutTy {
620- ty : self . arena . alloc ( hir:: Ty {
621- hir_id : self . next_id ( ) ,
622- kind : hir:: TyKind :: Path ( context_path) ,
623- span : self . lower_span ( span) ,
624- } ) ,
625- mutbl : hir:: Mutability :: Mut ,
626- } ;
599+ // Resume argument type: `ResumeTy`
600+ let unstable_span =
601+ self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
602+ let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span, None ) ;
627603 let input_ty = hir:: Ty {
628604 hir_id : self . next_id ( ) ,
629- kind : hir:: TyKind :: Rptr ( context_lifetime , context_ty ) ,
630- span : self . lower_span ( span ) ,
605+ kind : hir:: TyKind :: Path ( resume_ty ) ,
606+ span : unstable_span ,
631607 } ;
632608
633609 // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -686,9 +662,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
686662 . map_or ( false , |attrs| attrs. into_iter ( ) . any ( |attr| attr. has_name ( sym:: track_caller) ) ) ;
687663
688664 let hir_id = self . lower_node_id ( closure_node_id) ;
689- let unstable_span =
690- self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
691665 if track_caller {
666+ let unstable_span = self . mark_span_with_reason (
667+ DesugaringKind :: Async ,
668+ span,
669+ self . allow_gen_future . clone ( ) ,
670+ ) ;
692671 self . lower_attrs (
693672 hir_id,
694673 & [ Attribute {
@@ -731,7 +710,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
731710 /// mut __awaitee => loop {
732711 /// match unsafe { ::std::future::Future::poll(
733712 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
734- /// task_context,
713+ /// ::std::future::get_context( task_context) ,
735714 /// ) } {
736715 /// ::std::task::Poll::Ready(result) => break result,
737716 /// ::std::task::Poll::Pending => {}
@@ -772,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
772751 // unsafe {
773752 // ::std::future::Future::poll(
774753 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
775- // task_context,
754+ // ::std::future::get_context( task_context) ,
776755 // )
777756 // }
778757 let poll_expr = {
@@ -790,10 +769,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
790769 arena_vec ! [ self ; ref_mut_awaitee] ,
791770 Some ( expr_hir_id) ,
792771 ) ;
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+ ) ;
793778 let call = self . expr_call_lang_item_fn (
794779 span,
795780 hir:: LangItem :: FuturePoll ,
796- arena_vec ! [ self ; new_unchecked, task_context ] ,
781+ arena_vec ! [ self ; new_unchecked, get_context ] ,
797782 Some ( expr_hir_id) ,
798783 ) ;
799784 self . arena . alloc ( self . expr_unsafe ( call) )
0 commit comments