@@ -632,17 +632,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
632
632
) -> hir:: ExprKind < ' hir > {
633
633
let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
634
634
635
- // Resume argument type: `ResumeTy`
636
- let unstable_span = self . mark_span_with_reason (
637
- DesugaringKind :: Async ,
638
- self . lower_span ( span) ,
639
- Some ( self . allow_gen_future . clone ( ) ) ,
640
- ) ;
641
- let resume_ty = self . make_lang_item_qpath ( hir:: LangItem :: ResumeTy , unstable_span) ;
635
+ // Resume argument type: `&mut Context<'_>`.
636
+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
637
+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
638
+ hir_id : self . next_id ( ) ,
639
+ ident : context_lifetime_ident,
640
+ res : hir:: LifetimeName :: Infer ,
641
+ } ) ;
642
+ let context_path = hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) ) ;
643
+ let context_ty = hir:: MutTy {
644
+ ty : self . arena . alloc ( hir:: Ty {
645
+ hir_id : self . next_id ( ) ,
646
+ kind : hir:: TyKind :: Path ( context_path) ,
647
+ span : self . lower_span ( span) ,
648
+ } ) ,
649
+ mutbl : hir:: Mutability :: Mut ,
650
+ } ;
651
+
642
652
let input_ty = hir:: Ty {
643
653
hir_id : self . next_id ( ) ,
644
- kind : hir:: TyKind :: Path ( resume_ty ) ,
645
- span : unstable_span ,
654
+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
655
+ span : self . lower_span ( span ) ,
646
656
} ;
647
657
648
658
// The closure/coroutine `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -768,17 +778,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
768
778
) -> hir:: ExprKind < ' hir > {
769
779
let output = hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ;
770
780
771
- // Resume argument type: `ResumeTy`
772
- let unstable_span = self . mark_span_with_reason (
773
- DesugaringKind :: Async ,
774
- self . lower_span ( span) ,
775
- Some ( self . allow_gen_future . clone ( ) ) ,
776
- ) ;
777
- let resume_ty = self . make_lang_item_qpath ( hir:: LangItem :: ResumeTy , unstable_span) ;
781
+ // Resume argument type: `&mut Context<'_>`.
782
+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
783
+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
784
+ hir_id : self . next_id ( ) ,
785
+ ident : context_lifetime_ident,
786
+ res : hir:: LifetimeName :: Infer ,
787
+ } ) ;
788
+ let context_path = hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) ) ;
789
+ let context_ty = hir:: MutTy {
790
+ ty : self . arena . alloc ( hir:: Ty {
791
+ hir_id : self . next_id ( ) ,
792
+ kind : hir:: TyKind :: Path ( context_path) ,
793
+ span : self . lower_span ( span) ,
794
+ } ) ,
795
+ mutbl : hir:: Mutability :: Mut ,
796
+ } ;
797
+
778
798
let input_ty = hir:: Ty {
779
799
hir_id : self . next_id ( ) ,
780
- kind : hir:: TyKind :: Path ( resume_ty ) ,
781
- span : unstable_span ,
800
+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
801
+ span : self . lower_span ( span ) ,
782
802
} ;
783
803
784
804
// The closure/coroutine `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -871,7 +891,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
871
891
/// mut __awaitee => loop {
872
892
/// match unsafe { ::std::future::Future::poll(
873
893
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
874
- /// ::std::future::get_context( task_context) ,
894
+ /// task_context,
875
895
/// ) } {
876
896
/// ::std::task::Poll::Ready(result) => break result,
877
897
/// ::std::task::Poll::Pending => {}
@@ -912,29 +932,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
912
932
FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
913
933
} ;
914
934
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, features) ;
915
- let gen_future_span = self . mark_span_with_reason (
916
- DesugaringKind :: Await ,
917
- full_span,
918
- Some ( self . allow_gen_future . clone ( ) ) ,
919
- ) ;
920
935
let expr_hir_id = expr. hir_id ;
921
936
922
937
// Note that the name of this binding must not be changed to something else because
923
938
// debuggers and debugger extensions expect it to be called `__awaitee`. They use
924
939
// this name to identify what is being awaited by a suspended async functions.
925
940
let awaitee_ident = Ident :: with_dummy_span ( sym:: __awaitee) ;
926
- let ( awaitee_pat, awaitee_pat_hid) = self . pat_ident_binding_mode (
927
- gen_future_span,
928
- awaitee_ident,
929
- hir:: BindingAnnotation :: MUT ,
930
- ) ;
941
+ let ( awaitee_pat, awaitee_pat_hid) =
942
+ self . pat_ident_binding_mode ( full_span, awaitee_ident, hir:: BindingAnnotation :: MUT ) ;
931
943
932
944
let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
933
945
934
946
// unsafe {
935
947
// ::std::future::Future::poll(
936
948
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
937
- // ::std::future::get_context( task_context) ,
949
+ // task_context,
938
950
// )
939
951
// }
940
952
let poll_expr = {
@@ -952,21 +964,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
952
964
hir:: LangItem :: PinNewUnchecked ,
953
965
arena_vec ! [ self ; ref_mut_awaitee] ,
954
966
) ;
955
- let get_context = self . expr_call_lang_item_fn_mut (
956
- gen_future_span,
957
- hir:: LangItem :: GetContext ,
958
- arena_vec ! [ self ; task_context] ,
959
- ) ;
960
967
let call = match await_kind {
961
968
FutureKind :: Future => self . expr_call_lang_item_fn (
962
969
span,
963
970
hir:: LangItem :: FuturePoll ,
964
- arena_vec ! [ self ; new_unchecked, get_context ] ,
971
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
965
972
) ,
966
973
FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
967
974
span,
968
975
hir:: LangItem :: AsyncIteratorPollNext ,
969
- arena_vec ! [ self ; new_unchecked, get_context ] ,
976
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
970
977
) ,
971
978
} ;
972
979
self . arena . alloc ( self . expr_unsafe ( call) )
@@ -977,14 +984,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
977
984
let loop_hir_id = self . lower_node_id ( loop_node_id) ;
978
985
let ready_arm = {
979
986
let x_ident = Ident :: with_dummy_span ( sym:: result) ;
980
- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
981
- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
982
- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
987
+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
988
+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
989
+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
983
990
let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
984
991
let break_x = self . with_loop_scope ( loop_node_id, move |this| {
985
992
let expr_break =
986
993
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
987
- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
994
+ this. arena . alloc ( this. expr ( full_span , expr_break) )
988
995
} ) ;
989
996
self . arm ( ready_pat, break_x)
990
997
} ;
0 commit comments