@@ -346,9 +346,17 @@ static_assert_size!(TyKind<'_>, 24);
346346/// ## Generators
347347///
348348/// Generators are handled similarly in `GeneratorSubsts`. The set of
349- /// type parameters is similar, but the role of CK and CS are
350- /// different. CK represents the "yield type" and CS represents the
351- /// "return type" of the generator.
349+ /// type parameters is similar, but `CK` and `CS` are replaced by the
350+ /// following type parameters:
351+ ///
352+ /// * `GS`: The generator's "resume type", which is the type of the
353+ /// argument passed to `resume`, and the type of `yield` expressions
354+ /// inside the generator.
355+ /// * `GY`: The "yield type", which is the type of values passed to
356+ /// `yield` inside the generator.
357+ /// * `GR`: The "return type", which is the type of value returned upon
358+ /// completion of the generator.
359+ /// * `GW`: The "generator witness".
352360#[ derive( Copy , Clone , Debug , TypeFoldable ) ]
353361pub struct ClosureSubsts < ' tcx > {
354362 /// Lifetime and type parameters from the enclosing function,
@@ -442,6 +450,7 @@ pub struct GeneratorSubsts<'tcx> {
442450}
443451
444452struct SplitGeneratorSubsts < ' tcx > {
453+ resume_ty : Ty < ' tcx > ,
445454 yield_ty : Ty < ' tcx > ,
446455 return_ty : Ty < ' tcx > ,
447456 witness : Ty < ' tcx > ,
@@ -453,10 +462,11 @@ impl<'tcx> GeneratorSubsts<'tcx> {
453462 let generics = tcx. generics_of ( def_id) ;
454463 let parent_len = generics. parent_count ;
455464 SplitGeneratorSubsts {
456- yield_ty : self . substs . type_at ( parent_len) ,
457- return_ty : self . substs . type_at ( parent_len + 1 ) ,
458- witness : self . substs . type_at ( parent_len + 2 ) ,
459- upvar_kinds : & self . substs [ parent_len + 3 ..] ,
465+ resume_ty : self . substs . type_at ( parent_len) ,
466+ yield_ty : self . substs . type_at ( parent_len + 1 ) ,
467+ return_ty : self . substs . type_at ( parent_len + 2 ) ,
468+ witness : self . substs . type_at ( parent_len + 3 ) ,
469+ upvar_kinds : & self . substs [ parent_len + 4 ..] ,
460470 }
461471 }
462472
@@ -485,6 +495,11 @@ impl<'tcx> GeneratorSubsts<'tcx> {
485495 } )
486496 }
487497
498+ /// Returns the type representing the resume type of the generator.
499+ pub fn resume_ty ( self , def_id : DefId , tcx : TyCtxt < ' _ > ) -> Ty < ' tcx > {
500+ self . split ( def_id, tcx) . resume_ty
501+ }
502+
488503 /// Returns the type representing the yield type of the generator.
489504 pub fn yield_ty ( self , def_id : DefId , tcx : TyCtxt < ' _ > ) -> Ty < ' tcx > {
490505 self . split ( def_id, tcx) . yield_ty
@@ -505,10 +520,14 @@ impl<'tcx> GeneratorSubsts<'tcx> {
505520 ty:: Binder :: dummy ( self . sig ( def_id, tcx) )
506521 }
507522
508- /// Returns the "generator signature", which consists of its yield
523+ /// Returns the "generator signature", which consists of its resume, yield
509524 /// and return types.
510525 pub fn sig ( self , def_id : DefId , tcx : TyCtxt < ' _ > ) -> GenSig < ' tcx > {
511- ty:: GenSig { yield_ty : self . yield_ty ( def_id, tcx) , return_ty : self . return_ty ( def_id, tcx) }
526+ ty:: GenSig {
527+ resume_ty : self . resume_ty ( def_id, tcx) ,
528+ yield_ty : self . yield_ty ( def_id, tcx) ,
529+ return_ty : self . return_ty ( def_id, tcx) ,
530+ }
512531 }
513532}
514533
@@ -1072,13 +1091,17 @@ impl<'tcx> ProjectionTy<'tcx> {
10721091
10731092#[ derive( Clone , Debug , TypeFoldable ) ]
10741093pub struct GenSig < ' tcx > {
1094+ pub resume_ty : Ty < ' tcx > ,
10751095 pub yield_ty : Ty < ' tcx > ,
10761096 pub return_ty : Ty < ' tcx > ,
10771097}
10781098
10791099pub type PolyGenSig < ' tcx > = Binder < GenSig < ' tcx > > ;
10801100
10811101impl < ' tcx > PolyGenSig < ' tcx > {
1102+ pub fn resume_ty ( & self ) -> ty:: Binder < Ty < ' tcx > > {
1103+ self . map_bound_ref ( |sig| sig. resume_ty )
1104+ }
10821105 pub fn yield_ty ( & self ) -> ty:: Binder < Ty < ' tcx > > {
10831106 self . map_bound_ref ( |sig| sig. yield_ty )
10841107 }
0 commit comments