@@ -318,6 +318,7 @@ pub struct ClosureSubsts<'tcx> {
318
318
/// Struct returned by `split()`. Note that these are subslices of the
319
319
/// parent slice and not canonical substs themselves.
320
320
struct SplitClosureSubsts < ' tcx > {
321
+ parent : & ' tcx [ GenericArg < ' tcx > ] ,
321
322
closure_kind_ty : GenericArg < ' tcx > ,
322
323
closure_sig_as_fn_ptr_ty : GenericArg < ' tcx > ,
323
324
tupled_upvars_ty : GenericArg < ' tcx > ,
@@ -329,8 +330,13 @@ impl<'tcx> ClosureSubsts<'tcx> {
329
330
/// ordering.
330
331
fn split ( self ) -> SplitClosureSubsts < ' tcx > {
331
332
match self . substs [ ..] {
332
- [ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
333
- SplitClosureSubsts { closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty }
333
+ [ ref parent @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
334
+ SplitClosureSubsts {
335
+ parent,
336
+ closure_kind_ty,
337
+ closure_sig_as_fn_ptr_ty,
338
+ tupled_upvars_ty,
339
+ }
334
340
}
335
341
_ => bug ! ( "closure substs missing synthetics" ) ,
336
342
}
@@ -345,9 +351,20 @@ impl<'tcx> ClosureSubsts<'tcx> {
345
351
self . substs . len ( ) >= 3 && matches ! ( self . split( ) . tupled_upvars_ty. expect_ty( ) . kind, Tuple ( _) )
346
352
}
347
353
354
+ /// Returns the substitutions of the closure's parent.
355
+ pub fn parent_substs ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
356
+ self . split ( ) . parent
357
+ }
358
+
348
359
#[ inline]
349
360
pub fn upvar_tys ( self ) -> impl Iterator < Item = Ty < ' tcx > > + ' tcx {
350
- self . split ( ) . tupled_upvars_ty . expect_ty ( ) . tuple_fields ( )
361
+ self . tupled_upvars_ty ( ) . tuple_fields ( )
362
+ }
363
+
364
+ /// Returns the tuple type representing the upvars for this closure.
365
+ #[ inline]
366
+ pub fn tupled_upvars_ty ( self ) -> Ty < ' tcx > {
367
+ self . split ( ) . tupled_upvars_ty . expect_ty ( )
351
368
}
352
369
353
370
/// Returns the closure kind for this closure; may return a type
@@ -392,6 +409,7 @@ pub struct GeneratorSubsts<'tcx> {
392
409
}
393
410
394
411
struct SplitGeneratorSubsts < ' tcx > {
412
+ parent : & ' tcx [ GenericArg < ' tcx > ] ,
395
413
resume_ty : GenericArg < ' tcx > ,
396
414
yield_ty : GenericArg < ' tcx > ,
397
415
return_ty : GenericArg < ' tcx > ,
@@ -402,8 +420,15 @@ struct SplitGeneratorSubsts<'tcx> {
402
420
impl < ' tcx > GeneratorSubsts < ' tcx > {
403
421
fn split ( self ) -> SplitGeneratorSubsts < ' tcx > {
404
422
match self . substs [ ..] {
405
- [ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
406
- SplitGeneratorSubsts { resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty }
423
+ [ ref parent @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
424
+ SplitGeneratorSubsts {
425
+ parent,
426
+ resume_ty,
427
+ yield_ty,
428
+ return_ty,
429
+ witness,
430
+ tupled_upvars_ty,
431
+ }
407
432
}
408
433
_ => bug ! ( "generator substs missing synthetics" ) ,
409
434
}
@@ -418,6 +443,11 @@ impl<'tcx> GeneratorSubsts<'tcx> {
418
443
self . substs . len ( ) >= 5 && matches ! ( self . split( ) . tupled_upvars_ty. expect_ty( ) . kind, Tuple ( _) )
419
444
}
420
445
446
+ /// Returns the substitutions of the generator's parent.
447
+ pub fn parent_substs ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
448
+ self . split ( ) . parent
449
+ }
450
+
421
451
/// This describes the types that can be contained in a generator.
422
452
/// It will be a type variable initially and unified in the last stages of typeck of a body.
423
453
/// It contains a tuple of all the types that could end up on a generator frame.
@@ -429,7 +459,13 @@ impl<'tcx> GeneratorSubsts<'tcx> {
429
459
430
460
#[ inline]
431
461
pub fn upvar_tys ( self ) -> impl Iterator < Item = Ty < ' tcx > > + ' tcx {
432
- self . split ( ) . tupled_upvars_ty . expect_ty ( ) . tuple_fields ( )
462
+ self . tupled_upvars_ty ( ) . tuple_fields ( )
463
+ }
464
+
465
+ /// Returns the tuple type representing the upvars for this generator.
466
+ #[ inline]
467
+ pub fn tupled_upvars_ty ( self ) -> Ty < ' tcx > {
468
+ self . split ( ) . tupled_upvars_ty . expect_ty ( )
433
469
}
434
470
435
471
/// Returns the type representing the resume type of the generator.
0 commit comments