@@ -298,14 +298,10 @@ static_assert!(MEM_SIZE_OF_TY_KIND: ::std::mem::size_of::<TyKind<'_>>() == 24);
298
298
///
299
299
/// ## Generators
300
300
///
301
- /// Perhaps surprisingly, `ClosureSubsts` are also used for
302
- /// generators. In that case, what is written above is only half-true
303
- /// -- the set of type parameters is similar, but the role of CK and
304
- /// CS are different. CK represents the "yield type" and CS
305
- /// represents the "return type" of the generator.
306
- ///
307
- /// It'd be nice to split this struct into ClosureSubsts and
308
- /// GeneratorSubsts, I believe. -nmatsakis
301
+ /// Generators are handled similarly in `GeneratorSubsts`. The set of
302
+ /// type parameters is similar, but the role of CK and CS are
303
+ /// different. CK represents the "yield type" and CS represents the
304
+ /// "return type" of the generator.
309
305
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ,
310
306
Debug , RustcEncodable , RustcDecodable , HashStable ) ]
311
307
pub struct ClosureSubsts < ' tcx > {
@@ -391,6 +387,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
391
387
}
392
388
}
393
389
390
+ /// Similar to `ClosureSubsts`; see the above documentation for more.
394
391
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ,
395
392
RustcEncodable , RustcDecodable , HashStable ) ]
396
393
pub struct GeneratorSubsts < ' tcx > {
@@ -470,6 +467,11 @@ impl<'tcx> GeneratorSubsts<'tcx> {
470
467
}
471
468
472
469
impl < ' a , ' gcx , ' tcx > GeneratorSubsts < ' tcx > {
470
+ /// The type of the state "discriminant" used in the generator type.
471
+ pub fn discr_ty ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> Ty < ' tcx > {
472
+ tcx. types . u32
473
+ }
474
+
473
475
/// This returns the types of the MIR locals which had to be stored across suspension points.
474
476
/// It is calculated in rustc_mir::transform::generator::StateTransform.
475
477
/// All the types here must be in the tuple in GeneratorInterior.
@@ -484,15 +486,15 @@ impl<'a, 'gcx, 'tcx> GeneratorSubsts<'tcx> {
484
486
485
487
/// This is the types of the fields of a generate which
486
488
/// is available before the generator transformation.
487
- /// It includes the upvars and the state discriminant which is u32 .
489
+ /// It includes the upvars and the state discriminant.
488
490
pub fn pre_transforms_tys ( self , def_id : DefId , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) ->
489
491
impl Iterator < Item =Ty < ' tcx > > + ' a
490
492
{
491
- self . upvar_tys ( def_id, tcx) . chain ( iter:: once ( tcx . types . u32 ) )
493
+ self . upvar_tys ( def_id, tcx) . chain ( iter:: once ( self . discr_ty ( tcx ) ) )
492
494
}
493
495
494
496
/// This is the types of all the fields stored in a generator.
495
- /// It includes the upvars, state types and the state discriminant which is u32 .
497
+ /// It includes the upvars, state types and the state discriminant.
496
498
pub fn field_tys ( self , def_id : DefId , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) ->
497
499
impl Iterator < Item =Ty < ' tcx > > + Captures < ' gcx > + ' a
498
500
{
0 commit comments