@@ -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:: { sym, Ident , Symbol } ;
19
+ use rustc_span:: symbol:: { kw , sym, Ident , Symbol } ;
20
20
use rustc_span:: DUMMY_SP ;
21
21
use thin_vec:: thin_vec;
22
22
@@ -599,14 +599,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
599
599
) -> hir:: ExprKind < ' hir > {
600
600
let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
601
601
602
- // Resume argument type: `ResumeTy`
603
- let unstable_span =
604
- self . mark_span_with_reason ( DesugaringKind :: Async , span, self . allow_gen_future . clone ( ) ) ;
605
- let resume_ty = hir:: QPath :: LangItem ( hir:: LangItem :: ResumeTy , unstable_span, None ) ;
602
+ // Resume argument type: `&mut Context<'_>`.
603
+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
604
+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
605
+ hir_id : self . next_id ( ) ,
606
+ ident : context_lifetime_ident,
607
+ res : hir:: LifetimeName :: Infer ,
608
+ } ) ;
609
+ let context_path =
610
+ hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) , None ) ;
611
+ let context_ty = hir:: MutTy {
612
+ ty : self . arena . alloc ( hir:: Ty {
613
+ hir_id : self . next_id ( ) ,
614
+ kind : hir:: TyKind :: Path ( context_path) ,
615
+ span : self . lower_span ( span) ,
616
+ } ) ,
617
+ mutbl : hir:: Mutability :: Mut ,
618
+ } ;
619
+
606
620
let input_ty = hir:: Ty {
607
621
hir_id : self . next_id ( ) ,
608
- kind : hir:: TyKind :: Path ( resume_ty ) ,
609
- span : unstable_span ,
622
+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
623
+ span : self . lower_span ( span ) ,
610
624
} ;
611
625
612
626
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -710,7 +724,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
710
724
/// mut __awaitee => loop {
711
725
/// match unsafe { ::std::future::Future::poll(
712
726
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
713
- /// ::std::future::get_context( task_context) ,
727
+ /// task_context,
714
728
/// ) } {
715
729
/// ::std::task::Poll::Ready(result) => break result,
716
730
/// ::std::task::Poll::Pending => {}
@@ -731,11 +745,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
731
745
}
732
746
}
733
747
let span = self . mark_span_with_reason ( DesugaringKind :: Await , dot_await_span, None ) ;
734
- let gen_future_span = self . mark_span_with_reason (
735
- DesugaringKind :: Await ,
736
- full_span,
737
- self . allow_gen_future . clone ( ) ,
738
- ) ;
739
748
let expr = self . lower_expr_mut ( expr) ;
740
749
let expr_hir_id = expr. hir_id ;
741
750
@@ -751,7 +760,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
751
760
// unsafe {
752
761
// ::std::future::Future::poll(
753
762
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
754
- // ::std::future::get_context( task_context) ,
763
+ // task_context,
755
764
// )
756
765
// }
757
766
let poll_expr = {
@@ -769,16 +778,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
769
778
arena_vec ! [ self ; ref_mut_awaitee] ,
770
779
Some ( expr_hir_id) ,
771
780
) ;
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
- ) ;
778
781
let call = self . expr_call_lang_item_fn (
779
782
span,
780
783
hir:: LangItem :: FuturePoll ,
781
- arena_vec ! [ self ; new_unchecked, get_context ] ,
784
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
782
785
Some ( expr_hir_id) ,
783
786
) ;
784
787
self . arena . alloc ( self . expr_unsafe ( call) )
@@ -789,9 +792,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
789
792
let loop_hir_id = self . lower_node_id ( loop_node_id) ;
790
793
let ready_arm = {
791
794
let x_ident = Ident :: with_dummy_span ( sym:: result) ;
792
- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
793
- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
794
- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
795
+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
796
+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
797
+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
795
798
let ready_pat = self . pat_lang_item_variant (
796
799
span,
797
800
hir:: LangItem :: PollReady ,
@@ -801,7 +804,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
801
804
let break_x = self . with_loop_scope ( loop_node_id, move |this| {
802
805
let expr_break =
803
806
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
804
- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
807
+ this. arena . alloc ( this. expr ( full_span , expr_break) )
805
808
} ) ;
806
809
self . arm ( ready_pat, break_x)
807
810
} ;
0 commit comments