@@ -632,17 +632,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
632632 ) -> hir:: ExprKind < ' hir > {
633633 let output = ret_ty. unwrap_or_else ( || hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ) ;
634634
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+
642652 let input_ty = hir:: Ty {
643653 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 ) ,
646656 } ;
647657
648658 // The closure/coroutine `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -768,17 +778,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
768778 ) -> hir:: ExprKind < ' hir > {
769779 let output = hir:: FnRetTy :: DefaultReturn ( self . lower_span ( span) ) ;
770780
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+
778798 let input_ty = hir:: Ty {
779799 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 ) ,
782802 } ;
783803
784804 // The closure/coroutine `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -871,7 +891,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
871891 /// mut __awaitee => loop {
872892 /// match unsafe { ::std::future::Future::poll(
873893 /// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
874- /// ::std::future::get_context( task_context) ,
894+ /// task_context,
875895 /// ) } {
876896 /// ::std::task::Poll::Ready(result) => break result,
877897 /// ::std::task::Poll::Pending => {}
@@ -912,29 +932,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
912932 FutureKind :: AsyncIterator => Some ( self . allow_for_await . clone ( ) ) ,
913933 } ;
914934 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- ) ;
920935 let expr_hir_id = expr. hir_id ;
921936
922937 // Note that the name of this binding must not be changed to something else because
923938 // debuggers and debugger extensions expect it to be called `__awaitee`. They use
924939 // this name to identify what is being awaited by a suspended async functions.
925940 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 ) ;
931943
932944 let task_context_ident = Ident :: with_dummy_span ( sym:: _task_context) ;
933945
934946 // unsafe {
935947 // ::std::future::Future::poll(
936948 // ::std::pin::Pin::new_unchecked(&mut __awaitee),
937- // ::std::future::get_context( task_context) ,
949+ // task_context,
938950 // )
939951 // }
940952 let poll_expr = {
@@ -952,21 +964,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
952964 hir:: LangItem :: PinNewUnchecked ,
953965 arena_vec ! [ self ; ref_mut_awaitee] ,
954966 ) ;
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- ) ;
960967 let call = match await_kind {
961968 FutureKind :: Future => self . expr_call_lang_item_fn (
962969 span,
963970 hir:: LangItem :: FuturePoll ,
964- arena_vec ! [ self ; new_unchecked, get_context ] ,
971+ arena_vec ! [ self ; new_unchecked, task_context ] ,
965972 ) ,
966973 FutureKind :: AsyncIterator => self . expr_call_lang_item_fn (
967974 span,
968975 hir:: LangItem :: AsyncIteratorPollNext ,
969- arena_vec ! [ self ; new_unchecked, get_context ] ,
976+ arena_vec ! [ self ; new_unchecked, task_context ] ,
970977 ) ,
971978 } ;
972979 self . arena . alloc ( self . expr_unsafe ( call) )
@@ -977,14 +984,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
977984 let loop_hir_id = self . lower_node_id ( loop_node_id) ;
978985 let ready_arm = {
979986 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) ;
983990 let ready_pat = self . pat_lang_item_variant ( span, hir:: LangItem :: PollReady , ready_field) ;
984991 let break_x = self . with_loop_scope ( loop_node_id, move |this| {
985992 let expr_break =
986993 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) )
988995 } ) ;
989996 self . arm ( ready_pat, break_x)
990997 } ;
0 commit comments