@@ -715,18 +715,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
715
715
// whereas a generator does not.
716
716
let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
717
717
hir:: CoroutineDesugaring :: Async | hir:: CoroutineDesugaring :: AsyncGen => {
718
- // Resume argument type: `ResumeTy`
719
- let unstable_span = self . mark_span_with_reason (
720
- DesugaringKind :: Async ,
721
- self . lower_span ( span) ,
722
- Some ( Lrc :: clone ( & self . allow_gen_future ) ) ,
723
- ) ;
724
- let resume_ty =
725
- self . make_lang_item_qpath ( hir:: LangItem :: ResumeTy , unstable_span, None ) ;
718
+ // Resume argument type: `&mut Context<'_>`.
719
+ let context_lifetime_ident = Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ;
720
+ let context_lifetime = self . arena . alloc ( hir:: Lifetime {
721
+ hir_id : self . next_id ( ) ,
722
+ ident : context_lifetime_ident,
723
+ res : hir:: LifetimeName :: Infer ,
724
+ } ) ;
725
+ let context_path =
726
+ hir:: QPath :: LangItem ( hir:: LangItem :: Context , self . lower_span ( span) ) ;
727
+ let context_ty = hir:: MutTy {
728
+ ty : self . arena . alloc ( hir:: Ty {
729
+ hir_id : self . next_id ( ) ,
730
+ kind : hir:: TyKind :: Path ( context_path) ,
731
+ span : self . lower_span ( span) ,
732
+ } ) ,
733
+ mutbl : hir:: Mutability :: Mut ,
734
+ } ;
735
+
726
736
let input_ty = hir:: Ty {
727
737
hir_id : self . next_id ( ) ,
728
- kind : hir:: TyKind :: Path ( resume_ty ) ,
729
- span : unstable_span ,
738
+ kind : hir:: TyKind :: Ref ( context_lifetime , context_ty ) ,
739
+ span : self . lower_span ( span ) ,
730
740
} ;
731
741
let inputs = arena_vec ! [ self ; input_ty] ;
732
742
@@ -823,7 +833,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
823
833
/// mut __awaitee => loop {
824
834
/// match unsafe { ::std::future::Future::poll(
825
835
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
826
- /// ::std::future::get_context( task_context) ,
836
+ /// task_context,
827
837
/// ) } {
828
838
/// ::std::task::Poll::Ready(result) => break result,
829
839
/// ::std::task::Poll::Pending => {}
@@ -882,26 +892,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
882
892
FutureKind :: AsyncIterator => Some ( Lrc :: clone ( & self . allow_for_await ) ) ,
883
893
} ;
884
894
let span = self . mark_span_with_reason ( DesugaringKind :: Await , await_kw_span, features) ;
885
- let gen_future_span = self . mark_span_with_reason (
886
- DesugaringKind :: Await ,
887
- full_span,
888
- Some ( Lrc :: clone ( & self . allow_gen_future ) ) ,
889
- ) ;
890
895
let expr_hir_id = expr. hir_id ;
891
896
892
897
// Note that the name of this binding must not be changed to something else because
893
898
// debuggers and debugger extensions expect it to be called `__awaitee`. They use
894
899
// this name to identify what is being awaited by a suspended async functions.
895
900
let awaitee_ident = Ident :: with_dummy_span ( sym:: __awaitee) ;
896
901
let ( awaitee_pat, awaitee_pat_hid) =
897
- self . pat_ident_binding_mode ( gen_future_span , awaitee_ident, hir:: BindingMode :: MUT ) ;
902
+ self . pat_ident_binding_mode ( full_span , awaitee_ident, hir:: BindingMode :: MUT ) ;
898
903
899
904
let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
900
905
901
906
// unsafe {
902
907
// ::std::future::Future::poll(
903
908
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
904
- // ::std::future::get_context( task_context) ,
909
+ // task_context,
905
910
// )
906
911
// }
907
912
let poll_expr = {
@@ -919,21 +924,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
919
924
hir:: LangItem :: PinNewUnchecked ,
920
925
arena_vec ! [ self ; ref_mut_awaitee] ,
921
926
) ;
922
- let get_context = self . expr_call_lang_item_fn_mut (
923
- gen_future_span,
924
- hir:: LangItem :: GetContext ,
925
- arena_vec ! [ self ; task_context] ,
926
- ) ;
927
927
let call = match await_kind {
928
928
FutureKind :: Future => self . expr_call_lang_item_fn (
929
929
span,
930
930
hir:: LangItem :: FuturePoll ,
931
- arena_vec ! [ self ; new_unchecked, get_context ] ,
931
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
932
932
) ,
933
933
FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
934
934
span,
935
935
hir:: LangItem :: AsyncIteratorPollNext ,
936
- arena_vec ! [ self ; new_unchecked, get_context ] ,
936
+ arena_vec ! [ self ; new_unchecked, task_context ] ,
937
937
) ,
938
938
} ;
939
939
self . arena . alloc ( self . expr_unsafe ( call) )
@@ -944,14 +944,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
944
944
let loop_hir_id = self . lower_node_id ( loop_node_id) ;
945
945
let ready_arm = {
946
946
let x_ident = Ident :: with_dummy_span ( sym:: result) ;
947
- let ( x_pat, x_pat_hid) = self . pat_ident ( gen_future_span , x_ident) ;
948
- let x_expr = self . expr_ident ( gen_future_span , x_ident, x_pat_hid) ;
949
- let ready_field = self . single_pat_field ( gen_future_span , x_pat) ;
947
+ let ( x_pat, x_pat_hid) = self . pat_ident ( full_span , x_ident) ;
948
+ let x_expr = self . expr_ident ( full_span , x_ident, x_pat_hid) ;
949
+ let ready_field = self . single_pat_field ( full_span , x_pat) ;
950
950
let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
951
951
let break_x = self . with_loop_scope ( loop_hir_id, move |this| {
952
952
let expr_break =
953
953
hir:: ExprKind :: Break ( this. lower_loop_destination ( None ) , Some ( x_expr) ) ;
954
- this. arena . alloc ( this. expr ( gen_future_span , expr_break) )
954
+ this. arena . alloc ( this. expr ( full_span , expr_break) )
955
955
} ) ;
956
956
self . arm ( ready_pat, break_x)
957
957
} ;
0 commit comments