@@ -255,6 +255,17 @@ pub enum TypeVariants<'tcx> {
255
255
/// closure C wind up influencing the decisions we ought to make for
256
256
/// closure C (which would then require fixed point iteration to
257
257
/// handle). Plus it fixes an ICE. :P
258
+ ///
259
+ /// ## Generators
260
+ ///
261
+ /// Perhaps surprisingly, `ClosureSubsts` are also used for
262
+ /// generators. In that case, what is written above is only half-true
263
+ /// -- the set of type parameters is similar, but the role of CK and
264
+ /// CS are different. CK represents the "yield type" and CS
265
+ /// represents the "return type" of the generator.
266
+ ///
267
+ /// It'd be nice to split this struct into ClosureSubsts and
268
+ /// GeneratorSubsts, I believe. -nmatsakis
258
269
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
259
270
pub struct ClosureSubsts < ' tcx > {
260
271
/// Lifetime and type parameters from the enclosing function,
@@ -309,6 +320,31 @@ impl<'tcx> ClosureSubsts<'tcx> {
309
320
pub fn closure_sig_ty ( self , def_id : DefId , tcx : TyCtxt < ' _ , ' _ , ' _ > ) -> Ty < ' tcx > {
310
321
self . split ( def_id, tcx) . closure_sig_ty
311
322
}
323
+
324
+ /// Returns the type representing the yield type of the generator.
325
+ pub fn generator_yield_ty ( self , def_id : DefId , tcx : TyCtxt < ' _ , ' _ , ' _ > ) -> Ty < ' tcx > {
326
+ self . closure_kind_ty ( def_id, tcx)
327
+ }
328
+
329
+ /// Returns the type representing the return type of the generator.
330
+ pub fn generator_return_ty ( self , def_id : DefId , tcx : TyCtxt < ' _ , ' _ , ' _ > ) -> Ty < ' tcx > {
331
+ self . closure_sig_ty ( def_id, tcx)
332
+ }
333
+
334
+ /// Return the "generator signature", which consists of its yield
335
+ /// and return types.
336
+ ///
337
+ /// NB. We treat this as a `PolyGenSig`, but since it only
338
+ /// contains associated types of the generator, at present it
339
+ /// never binds any regions.
340
+ pub fn generator_poly_sig ( self , def_id : DefId , tcx : TyCtxt < ' _ , ' _ , ' _ > ) -> PolyGenSig < ' tcx > {
341
+ ty:: Binder (
342
+ ty:: GenSig {
343
+ yield_ty : self . generator_yield_ty ( def_id, tcx) ,
344
+ return_ty : self . generator_return_ty ( def_id, tcx) ,
345
+ }
346
+ )
347
+ }
312
348
}
313
349
314
350
impl < ' tcx > ClosureSubsts < ' tcx > {
0 commit comments