@@ -488,17 +488,17 @@ fn construct_fn<'tcx>(
488
488
489
489
let arguments = & thir. params ;
490
490
491
- let ( yield_ty, return_ty) = if coroutine_kind. is_some ( ) {
491
+ let ( resume_ty , yield_ty, return_ty) = if coroutine_kind. is_some ( ) {
492
492
let coroutine_ty = arguments[ thir:: UPVAR_ENV_PARAM ] . ty ;
493
493
let coroutine_sig = match coroutine_ty. kind ( ) {
494
494
ty:: Coroutine ( _, gen_args, ..) => gen_args. as_coroutine ( ) . sig ( ) ,
495
495
_ => {
496
496
span_bug ! ( span, "coroutine w/o coroutine type: {:?}" , coroutine_ty)
497
497
}
498
498
} ;
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 )
500
500
} else {
501
- ( None , fn_sig. output ( ) )
501
+ ( None , None , fn_sig. output ( ) )
502
502
} ;
503
503
504
504
if let Some ( custom_mir_attr) =
@@ -562,9 +562,12 @@ fn construct_fn<'tcx>(
562
562
} else {
563
563
None
564
564
} ;
565
- if yield_ty. is_some ( ) {
565
+
566
+ if coroutine_kind. is_some ( ) {
566
567
body. coroutine . as_mut ( ) . unwrap ( ) . yield_ty = yield_ty;
568
+ body. coroutine . as_mut ( ) . unwrap ( ) . resume_ty = resume_ty;
567
569
}
570
+
568
571
body
569
572
}
570
573
@@ -631,28 +634,29 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
631
634
let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
632
635
let coroutine_kind = tcx. coroutine_kind ( def_id) ;
633
636
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) {
635
638
DefKind :: Const
636
639
| DefKind :: AssocConst
637
640
| DefKind :: AnonConst
638
641
| 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 ) ,
640
643
DefKind :: Ctor ( ..) | DefKind :: Fn | DefKind :: AssocFn => {
641
644
let sig = tcx. liberate_late_bound_regions (
642
645
def_id. to_def_id ( ) ,
643
646
tcx. fn_sig ( def_id) . instantiate_identity ( ) ,
644
647
) ;
645
- ( sig. inputs ( ) . to_vec ( ) , sig. output ( ) , None )
648
+ ( sig. inputs ( ) . to_vec ( ) , sig. output ( ) , None , None )
646
649
}
647
650
DefKind :: Closure if coroutine_kind. is_some ( ) => {
648
651
let coroutine_ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
649
652
let ty:: Coroutine ( _, args) = coroutine_ty. kind ( ) else {
650
653
bug ! ( "expected type of coroutine-like closure to be a coroutine" )
651
654
} ;
652
655
let args = args. as_coroutine ( ) ;
656
+ let resume_ty = args. resume_ty ( ) ;
653
657
let yield_ty = args. yield_ty ( ) ;
654
658
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) )
656
660
}
657
661
DefKind :: Closure => {
658
662
let closure_ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
@@ -666,7 +670,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
666
670
ty:: ClosureKind :: FnMut => Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , closure_ty) ,
667
671
ty:: ClosureKind :: FnOnce => closure_ty,
668
672
} ;
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 )
670
674
}
671
675
dk => bug ! ( "{:?} is not a body: {:?}" , def_id, dk) ,
672
676
} ;
@@ -705,7 +709,10 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
705
709
Some ( guar) ,
706
710
) ;
707
711
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
+ } ) ;
709
716
710
717
body
711
718
}
0 commit comments