@@ -475,13 +475,15 @@ impl<'tcx> CoroutineClosureSignature<'tcx> {
475
475
self ,
476
476
tcx : TyCtxt < ' tcx > ,
477
477
parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
478
+ kind_ty : Ty < ' tcx > ,
478
479
coroutine_def_id : DefId ,
479
480
tupled_upvars_ty : Ty < ' tcx > ,
480
481
) -> Ty < ' tcx > {
481
482
let coroutine_args = ty:: CoroutineArgs :: new (
482
483
tcx,
483
484
ty:: CoroutineArgsParts {
484
485
parent_args,
486
+ kind_ty,
485
487
resume_ty : self . resume_ty ,
486
488
yield_ty : self . yield_ty ,
487
489
return_ty : self . return_ty ,
@@ -512,7 +514,13 @@ impl<'tcx> CoroutineClosureSignature<'tcx> {
512
514
env_region,
513
515
) ;
514
516
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
+ )
516
524
}
517
525
518
526
/// Given a closure kind, compute the tupled upvars that the given coroutine would return.
@@ -564,6 +572,8 @@ pub struct CoroutineArgs<'tcx> {
564
572
pub struct CoroutineArgsParts < ' tcx > {
565
573
/// This is the args of the typeck root.
566
574
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
575
+ // TODO: why
576
+ pub kind_ty : Ty < ' tcx > ,
567
577
pub resume_ty : Ty < ' tcx > ,
568
578
pub yield_ty : Ty < ' tcx > ,
569
579
pub return_ty : Ty < ' tcx > ,
@@ -582,6 +592,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
582
592
pub fn new ( tcx : TyCtxt < ' tcx > , parts : CoroutineArgsParts < ' tcx > ) -> CoroutineArgs < ' tcx > {
583
593
CoroutineArgs {
584
594
args : tcx. mk_args_from_iter ( parts. parent_args . iter ( ) . copied ( ) . chain ( [
595
+ parts. kind_ty . into ( ) ,
585
596
parts. resume_ty . into ( ) ,
586
597
parts. yield_ty . into ( ) ,
587
598
parts. return_ty . into ( ) ,
@@ -595,16 +606,23 @@ impl<'tcx> CoroutineArgs<'tcx> {
595
606
/// The ordering assumed here must match that used by `CoroutineArgs::new` above.
596
607
fn split ( self ) -> CoroutineArgsParts < ' tcx > {
597
608
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
+ } ,
608
626
_ => bug ! ( "coroutine args missing synthetics" ) ,
609
627
}
610
628
}
@@ -614,6 +632,11 @@ impl<'tcx> CoroutineArgs<'tcx> {
614
632
self . split ( ) . parent_args
615
633
}
616
634
635
+ // TODO:
636
+ pub fn kind_ty ( self ) -> Ty < ' tcx > {
637
+ self . split ( ) . kind_ty
638
+ }
639
+
617
640
/// This describes the types that can be contained in a coroutine.
618
641
/// It will be a type variable initially and unified in the last stages of typeck of a body.
619
642
/// It contains a tuple of all the types that could end up on a coroutine frame.
@@ -2381,7 +2404,7 @@ impl<'tcx> Ty<'tcx> {
2381
2404
) -> Ty < ' tcx > {
2382
2405
debug_assert_eq ! (
2383
2406
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 ,
2385
2408
"coroutine constructed with incorrect number of substitutions"
2386
2409
) ;
2387
2410
Ty :: new ( tcx, Coroutine ( def_id, coroutine_args) )
0 commit comments