@@ -475,13 +475,15 @@ impl<'tcx> CoroutineClosureSignature<'tcx> {
475475 self ,
476476 tcx : TyCtxt < ' tcx > ,
477477 parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
478+ kind_ty : Ty < ' tcx > ,
478479 coroutine_def_id : DefId ,
479480 tupled_upvars_ty : Ty < ' tcx > ,
480481 ) -> Ty < ' tcx > {
481482 let coroutine_args = ty:: CoroutineArgs :: new (
482483 tcx,
483484 ty:: CoroutineArgsParts {
484485 parent_args,
486+ kind_ty,
485487 resume_ty : self . resume_ty ,
486488 yield_ty : self . yield_ty ,
487489 return_ty : self . return_ty ,
@@ -512,7 +514,13 @@ impl<'tcx> CoroutineClosureSignature<'tcx> {
512514 env_region,
513515 ) ;
514516
515- self . to_coroutine ( tcx, parent_args, coroutine_def_id, tupled_upvars_ty)
517+ self . to_coroutine (
518+ tcx,
519+ parent_args,
520+ Ty :: from_closure_kind ( tcx, closure_kind) ,
521+ coroutine_def_id,
522+ tupled_upvars_ty,
523+ )
516524 }
517525
518526 /// Given a closure kind, compute the tupled upvars that the given coroutine would return.
@@ -564,6 +572,8 @@ pub struct CoroutineArgs<'tcx> {
564572pub struct CoroutineArgsParts < ' tcx > {
565573 /// This is the args of the typeck root.
566574 pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
575+ // TODO: why
576+ pub kind_ty : Ty < ' tcx > ,
567577 pub resume_ty : Ty < ' tcx > ,
568578 pub yield_ty : Ty < ' tcx > ,
569579 pub return_ty : Ty < ' tcx > ,
@@ -582,6 +592,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
582592 pub fn new ( tcx : TyCtxt < ' tcx > , parts : CoroutineArgsParts < ' tcx > ) -> CoroutineArgs < ' tcx > {
583593 CoroutineArgs {
584594 args : tcx. mk_args_from_iter ( parts. parent_args . iter ( ) . copied ( ) . chain ( [
595+ parts. kind_ty . into ( ) ,
585596 parts. resume_ty . into ( ) ,
586597 parts. yield_ty . into ( ) ,
587598 parts. return_ty . into ( ) ,
@@ -595,16 +606,23 @@ impl<'tcx> CoroutineArgs<'tcx> {
595606 /// The ordering assumed here must match that used by `CoroutineArgs::new` above.
596607 fn split ( self ) -> CoroutineArgsParts < ' tcx > {
597608 match self . args [ ..] {
598- [ ref parent_args @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
599- CoroutineArgsParts {
600- parent_args,
601- resume_ty : resume_ty. expect_ty ( ) ,
602- yield_ty : yield_ty. expect_ty ( ) ,
603- return_ty : return_ty. expect_ty ( ) ,
604- witness : witness. expect_ty ( ) ,
605- tupled_upvars_ty : tupled_upvars_ty. expect_ty ( ) ,
606- }
607- }
609+ [
610+ ref parent_args @ ..,
611+ kind_ty,
612+ resume_ty,
613+ yield_ty,
614+ return_ty,
615+ witness,
616+ tupled_upvars_ty,
617+ ] => CoroutineArgsParts {
618+ parent_args,
619+ kind_ty : kind_ty. expect_ty ( ) ,
620+ resume_ty : resume_ty. expect_ty ( ) ,
621+ yield_ty : yield_ty. expect_ty ( ) ,
622+ return_ty : return_ty. expect_ty ( ) ,
623+ witness : witness. expect_ty ( ) ,
624+ tupled_upvars_ty : tupled_upvars_ty. expect_ty ( ) ,
625+ } ,
608626 _ => bug ! ( "coroutine args missing synthetics" ) ,
609627 }
610628 }
@@ -614,6 +632,11 @@ impl<'tcx> CoroutineArgs<'tcx> {
614632 self . split ( ) . parent_args
615633 }
616634
635+ // TODO:
636+ pub fn kind_ty ( self ) -> Ty < ' tcx > {
637+ self . split ( ) . kind_ty
638+ }
639+
617640 /// This describes the types that can be contained in a coroutine.
618641 /// It will be a type variable initially and unified in the last stages of typeck of a body.
619642 /// It contains a tuple of all the types that could end up on a coroutine frame.
@@ -2381,7 +2404,7 @@ impl<'tcx> Ty<'tcx> {
23812404 ) -> Ty < ' tcx > {
23822405 debug_assert_eq ! (
23832406 coroutine_args. len( ) ,
2384- tcx. generics_of( tcx. typeck_root_def_id( def_id) ) . count( ) + 5 ,
2407+ tcx. generics_of( tcx. typeck_root_def_id( def_id) ) . count( ) + 6 ,
23852408 "coroutine constructed with incorrect number of substitutions"
23862409 ) ;
23872410 Ty :: new ( tcx, Coroutine ( def_id, coroutine_args) )
0 commit comments