@@ -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
@@ -585,38 +585,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
585
585
) -> hir:: ExprKind < ' hir > {
586
586
let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
587
587
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 ) ;
616
592
let input_ty = hir:: Ty {
617
593
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 ,
620
596
} ;
621
597
622
598
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -674,9 +650,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
674
650
. map_or ( false , |attrs| attrs. into_iter ( ) . any ( |attr| attr. has_name ( sym:: track_caller) ) ) ;
675
651
676
652
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 ( ) ) ;
679
653
if track_caller {
654
+ let unstable_span = self . mark_span_with_reason (
655
+ DesugaringKind :: Async ,
656
+ span,
657
+ self . allow_gen_future . clone ( ) ,
658
+ ) ;
680
659
self . lower_attrs (
681
660
hir_id,
682
661
& [ Attribute {
@@ -719,7 +698,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
719
698
/// mut __awaitee => loop {
720
699
/// match unsafe { ::std::future::Future::poll(
721
700
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
722
- /// task_context,
701
+ /// ::std::future::get_context( task_context) ,
723
702
/// ) } {
724
703
/// ::std::task::Poll::Ready(result) => break result,
725
704
/// ::std::task::Poll::Pending => {}
@@ -760,7 +739,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
760
739
// unsafe {
761
740
// ::std::future::Future::poll(
762
741
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
763
- // task_context,
742
+ // ::std::future::get_context( task_context) ,
764
743
// )
765
744
// }
766
745
let poll_expr = {
@@ -778,10 +757,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
778
757
arena_vec ! [ self ; ref_mut_awaitee] ,
779
758
Some ( expr_hir_id) ,
780
759
) ;
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
+ ) ;
781
766
let call = self . expr_call_lang_item_fn (
782
767
span,
783
768
hir:: LangItem :: FuturePoll ,
784
- arena_vec ! [ self ; new_unchecked, task_context ] ,
769
+ arena_vec ! [ self ; new_unchecked, get_context ] ,
785
770
Some ( expr_hir_id) ,
786
771
) ;
787
772
self . arena . alloc ( self . expr_unsafe ( call) )
0 commit comments