@@ -318,6 +318,7 @@ pub struct ClosureSubsts<'tcx> {
318318/// Struct returned by `split()`. Note that these are subslices of the
319319/// parent slice and not canonical substs themselves.
320320struct SplitClosureSubsts < ' tcx > {
321+ parent : & ' tcx [ GenericArg < ' tcx > ] ,
321322 closure_kind_ty : GenericArg < ' tcx > ,
322323 closure_sig_as_fn_ptr_ty : GenericArg < ' tcx > ,
323324 tupled_upvars_ty : GenericArg < ' tcx > ,
@@ -329,8 +330,13 @@ impl<'tcx> ClosureSubsts<'tcx> {
329330 /// ordering.
330331 fn split ( self ) -> SplitClosureSubsts < ' tcx > {
331332 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+ }
334340 }
335341 _ => bug ! ( "closure substs missing synthetics" ) ,
336342 }
@@ -345,9 +351,20 @@ impl<'tcx> ClosureSubsts<'tcx> {
345351 self . substs . len ( ) >= 3 && matches ! ( self . split( ) . tupled_upvars_ty. expect_ty( ) . kind, Tuple ( _) )
346352 }
347353
354+ /// Returns the substitutions of the closure's parent.
355+ pub fn parent_substs ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
356+ self . split ( ) . parent
357+ }
358+
348359 #[ inline]
349360 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 ( )
351368 }
352369
353370 /// Returns the closure kind for this closure; may return a type
@@ -392,6 +409,7 @@ pub struct GeneratorSubsts<'tcx> {
392409}
393410
394411struct SplitGeneratorSubsts < ' tcx > {
412+ parent : & ' tcx [ GenericArg < ' tcx > ] ,
395413 resume_ty : GenericArg < ' tcx > ,
396414 yield_ty : GenericArg < ' tcx > ,
397415 return_ty : GenericArg < ' tcx > ,
@@ -402,8 +420,15 @@ struct SplitGeneratorSubsts<'tcx> {
402420impl < ' tcx > GeneratorSubsts < ' tcx > {
403421 fn split ( self ) -> SplitGeneratorSubsts < ' tcx > {
404422 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+ }
407432 }
408433 _ => bug ! ( "generator substs missing synthetics" ) ,
409434 }
@@ -418,6 +443,11 @@ impl<'tcx> GeneratorSubsts<'tcx> {
418443 self . substs . len ( ) >= 5 && matches ! ( self . split( ) . tupled_upvars_ty. expect_ty( ) . kind, Tuple ( _) )
419444 }
420445
446+ /// Returns the substitutions of the generator's parent.
447+ pub fn parent_substs ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
448+ self . split ( ) . parent
449+ }
450+
421451 /// This describes the types that can be contained in a generator.
422452 /// It will be a type variable initially and unified in the last stages of typeck of a body.
423453 /// It contains a tuple of all the types that could end up on a generator frame.
@@ -429,7 +459,13 @@ impl<'tcx> GeneratorSubsts<'tcx> {
429459
430460 #[ inline]
431461 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 ( )
433469 }
434470
435471 /// Returns the type representing the resume type of the generator.
0 commit comments