@@ -488,17 +488,17 @@ fn construct_fn<'tcx>(
488488
489489 let arguments = & thir. params ;
490490
491- let ( yield_ty, return_ty) = if coroutine_kind. is_some ( ) {
491+ let ( resume_ty , yield_ty, return_ty) = if coroutine_kind. is_some ( ) {
492492 let coroutine_ty = arguments[ thir:: UPVAR_ENV_PARAM ] . ty ;
493493 let coroutine_sig = match coroutine_ty. kind ( ) {
494494 ty:: Coroutine ( _, gen_args, ..) => gen_args. as_coroutine ( ) . sig ( ) ,
495495 _ => {
496496 span_bug ! ( span, "coroutine w/o coroutine type: {:?}" , coroutine_ty)
497497 }
498498 } ;
499- ( Some ( coroutine_sig. yield_ty ) , coroutine_sig. return_ty )
499+ ( Some ( coroutine_sig. resume_ty ) , Some ( coroutine_sig . yield_ty ) , coroutine_sig. return_ty )
500500 } else {
501- ( None , fn_sig. output ( ) )
501+ ( None , None , fn_sig. output ( ) )
502502 } ;
503503
504504 if let Some ( custom_mir_attr) =
@@ -562,9 +562,12 @@ fn construct_fn<'tcx>(
562562 } else {
563563 None
564564 } ;
565- if yield_ty. is_some ( ) {
565+
566+ if coroutine_kind. is_some ( ) {
566567 body. coroutine . as_mut ( ) . unwrap ( ) . yield_ty = yield_ty;
568+ body. coroutine . as_mut ( ) . unwrap ( ) . resume_ty = resume_ty;
567569 }
570+
568571 body
569572}
570573
@@ -631,28 +634,29 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
631634 let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
632635 let coroutine_kind = tcx. coroutine_kind ( def_id) ;
633636
634- let ( inputs, output, yield_ty) = match tcx. def_kind ( def_id) {
637+ let ( inputs, output, resume_ty , yield_ty) = match tcx. def_kind ( def_id) {
635638 DefKind :: Const
636639 | DefKind :: AssocConst
637640 | DefKind :: AnonConst
638641 | DefKind :: InlineConst
639- | DefKind :: Static ( _) => ( vec ! [ ] , tcx. type_of ( def_id) . instantiate_identity ( ) , None ) ,
642+ | DefKind :: Static ( _) => ( vec ! [ ] , tcx. type_of ( def_id) . instantiate_identity ( ) , None , None ) ,
640643 DefKind :: Ctor ( ..) | DefKind :: Fn | DefKind :: AssocFn => {
641644 let sig = tcx. liberate_late_bound_regions (
642645 def_id. to_def_id ( ) ,
643646 tcx. fn_sig ( def_id) . instantiate_identity ( ) ,
644647 ) ;
645- ( sig. inputs ( ) . to_vec ( ) , sig. output ( ) , None )
648+ ( sig. inputs ( ) . to_vec ( ) , sig. output ( ) , None , None )
646649 }
647650 DefKind :: Closure if coroutine_kind. is_some ( ) => {
648651 let coroutine_ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
649652 let ty:: Coroutine ( _, args) = coroutine_ty. kind ( ) else {
650653 bug ! ( "expected type of coroutine-like closure to be a coroutine" )
651654 } ;
652655 let args = args. as_coroutine ( ) ;
656+ let resume_ty = args. resume_ty ( ) ;
653657 let yield_ty = args. yield_ty ( ) ;
654658 let return_ty = args. return_ty ( ) ;
655- ( vec ! [ coroutine_ty, args. resume_ty( ) ] , return_ty, Some ( yield_ty) )
659+ ( vec ! [ coroutine_ty, args. resume_ty( ) ] , return_ty, Some ( resume_ty ) , Some ( yield_ty) )
656660 }
657661 DefKind :: Closure => {
658662 let closure_ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
@@ -666,7 +670,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
666670 ty:: ClosureKind :: FnMut => Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , closure_ty) ,
667671 ty:: ClosureKind :: FnOnce => closure_ty,
668672 } ;
669- ( [ self_ty] . into_iter ( ) . chain ( sig. inputs ( ) . to_vec ( ) ) . collect ( ) , sig. output ( ) , None )
673+ ( [ self_ty] . into_iter ( ) . chain ( sig. inputs ( ) . to_vec ( ) ) . collect ( ) , sig. output ( ) , None , None )
670674 }
671675 dk => bug ! ( "{:?} is not a body: {:?}" , def_id, dk) ,
672676 } ;
@@ -705,7 +709,10 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
705709 Some ( guar) ,
706710 ) ;
707711
708- body. coroutine . as_mut ( ) . map ( |gen| gen. yield_ty = yield_ty) ;
712+ body. coroutine . as_mut ( ) . map ( |gen| {
713+ gen. yield_ty = yield_ty;
714+ gen. resume_ty = resume_ty;
715+ } ) ;
709716
710717 body
711718}
0 commit comments