@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
16
16
use rustc_hir:: definitions:: DefPathData ;
17
17
use rustc_session:: errors:: report_lit_error;
18
18
use rustc_span:: source_map:: { respan, DesugaringKind , Span , Spanned } ;
19
- use rustc_span:: symbol:: { kw , sym, Ident } ;
19
+ use rustc_span:: symbol:: { sym, Ident } ;
20
20
use rustc_span:: DUMMY_SP ;
21
21
use thin_vec:: thin_vec;
22
22
@@ -596,38 +596,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
596
596
) -> hir:: ExprKind < ' hir > {
597
597
let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
598
598
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 ) ;
627
603
let input_ty = hir:: Ty {
628
604
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 ,
631
607
} ;
632
608
633
609
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -686,9 +662,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
686
662
. map_or ( false , |attrs| attrs. into_iter ( ) . any ( |attr| attr. has_name ( sym:: track_caller) ) ) ;
687
663
688
664
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 ( ) ) ;
691
665
if track_caller {
666
+ let unstable_span = self . mark_span_with_reason (
667
+ DesugaringKind :: Async ,
668
+ span,
669
+ self . allow_gen_future . clone ( ) ,
670
+ ) ;
692
671
self . lower_attrs (
693
672
hir_id,
694
673
& [ Attribute {
@@ -731,7 +710,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
731
710
/// mut __awaitee => loop {
732
711
/// match unsafe { ::std::future::Future::poll(
733
712
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
734
- /// task_context,
713
+ /// ::std::future::get_context( task_context) ,
735
714
/// ) } {
736
715
/// ::std::task::Poll::Ready(result) => break result,
737
716
/// ::std::task::Poll::Pending => {}
@@ -772,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
772
751
// unsafe {
773
752
// ::std::future::Future::poll(
774
753
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
775
- // task_context,
754
+ // ::std::future::get_context( task_context) ,
776
755
// )
777
756
// }
778
757
let poll_expr = {
@@ -790,10 +769,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
790
769
arena_vec ! [ self ; ref_mut_awaitee] ,
791
770
Some ( expr_hir_id) ,
792
771
) ;
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
+ ) ;
793
778
let call = self . expr_call_lang_item_fn (
794
779
span,
795
780
hir:: LangItem :: FuturePoll ,
796
- arena_vec ! [ self ; new_unchecked, task_context ] ,
781
+ arena_vec ! [ self ; new_unchecked, get_context ] ,
797
782
Some ( expr_hir_id) ,
798
783
) ;
799
784
self . arena . alloc ( self . expr_unsafe ( call) )
0 commit comments