@@ -715,18 +715,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
715715 // whereas a generator does not.
716716 let ( inputs, params, task_context) : ( & [ _ ] , & [ _ ] , _ ) = match desugaring_kind {
717717 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+
726736 let input_ty = hir:: Ty {
727737 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 ) ,
730740 } ;
731741 let inputs = arena_vec ! [ self ; input_ty] ;
732742
@@ -823,7 +833,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
823833 /// mut __awaitee => loop {
824834 /// match unsafe { ::std::future::Future::poll(
825835 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
826- /// ::std::future::get_context( task_context) ,
836+ /// task_context,
827837 /// ) } {
828838 /// ::std::task::Poll::Ready(result) => break result,
829839 /// ::std::task::Poll::Pending => {}
@@ -882,26 +892,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
882892 FutureKind :: AsyncIterator => Some ( Lrc :: clone ( & self . allow_for_await ) ) ,
883893 } ;
884894 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- ) ;
890895 let expr_hir_id = expr. hir_id ;
891896
892897 // Note that the name of this binding must not be changed to something else because
893898 // debuggers and debugger extensions expect it to be called `__awaitee`. They use
894899 // this name to identify what is being awaited by a suspended async functions.
895900 let awaitee_ident = Ident :: with_dummy_span ( sym:: __awaitee) ;
896901 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 ) ;
898903
899904 let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
900905
901906 // unsafe {
902907 // ::std::future::Future::poll(
903908 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
904- // ::std::future::get_context( task_context) ,
909+ // task_context,
905910 // )
906911 // }
907912 let poll_expr = {
@@ -919,21 +924,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
919924 hir:: LangItem :: PinNewUnchecked ,
920925 arena_vec ! [ self ; ref_mut_awaitee] ,
921926 ) ;
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- ) ;
927927 let call = match await_kind {
928928 FutureKind :: Future => self . expr_call_lang_item_fn (
929929 span,
930930 hir:: LangItem :: FuturePoll ,
931- arena_vec ! [ self ; new_unchecked, get_context ] ,
931+ arena_vec ! [ self ; new_unchecked, task_context ] ,
932932 ) ,
933933 FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
934934 span,
935935 hir:: LangItem :: AsyncIteratorPollNext ,
936- arena_vec ! [ self ; new_unchecked, get_context ] ,
936+ arena_vec ! [ self ; new_unchecked, task_context ] ,
937937 ) ,
938938 } ;
939939 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -944,14 +944,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
944944 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
945945 let ready_arm = {
946946 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) ;
950950 let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
951951 let break_x = self . with_loop_scope ( loop_hir_id, move |this| {
952952 let expr_break =
953953 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) )
955955 } ) ;
956956 self . arm ( ready_pat, break_x)
957957 } ;
0 commit comments