@@ -388,9 +388,19 @@ impl<'tcx> ClosureSubsts<'tcx> {
388
388
self . split ( ) . parent_substs
389
389
}
390
390
391
+ /// Returns an iterator over the list of types of captured paths by the closure.
392
+ /// In case there was a type error in figuring out the types of the captured path, an
393
+ /// empty iterator is returned.
391
394
#[ inline]
392
395
pub fn upvar_tys ( self ) -> impl Iterator < Item = Ty < ' tcx > > + ' tcx {
393
- self . tupled_upvars_ty ( ) . tuple_fields ( )
396
+ match self . tupled_upvars_ty ( ) . kind ( ) {
397
+ TyKind :: Error ( _) => None ,
398
+ TyKind :: Tuple ( ..) => Some ( self . tupled_upvars_ty ( ) . tuple_fields ( ) ) ,
399
+ TyKind :: Infer ( _) => bug ! ( "upvar_tys called before capture types are inferred" ) ,
400
+ ty => bug ! ( "Unexpected representation of upvar types tuple {:?}" , ty) ,
401
+ }
402
+ . into_iter ( )
403
+ . flatten ( )
394
404
}
395
405
396
406
/// Returns the tuple type representing the upvars for this closure.
@@ -515,9 +525,19 @@ impl<'tcx> GeneratorSubsts<'tcx> {
515
525
self . split ( ) . witness . expect_ty ( )
516
526
}
517
527
528
+ /// Returns an iterator over the list of types of captured paths by the generator.
529
+ /// In case there was a type error in figuring out the types of the captured path, an
530
+ /// empty iterator is returned.
518
531
#[ inline]
519
532
pub fn upvar_tys ( self ) -> impl Iterator < Item = Ty < ' tcx > > + ' tcx {
520
- self . tupled_upvars_ty ( ) . tuple_fields ( )
533
+ match self . tupled_upvars_ty ( ) . kind ( ) {
534
+ TyKind :: Error ( _) => None ,
535
+ TyKind :: Tuple ( ..) => Some ( self . tupled_upvars_ty ( ) . tuple_fields ( ) ) ,
536
+ TyKind :: Infer ( _) => bug ! ( "upvar_tys called before capture types are inferred" ) ,
537
+ ty => bug ! ( "Unexpected representation of upvar types tuple {:?}" , ty) ,
538
+ }
539
+ . into_iter ( )
540
+ . flatten ( )
521
541
}
522
542
523
543
/// Returns the tuple type representing the upvars for this generator.
@@ -660,13 +680,24 @@ pub enum UpvarSubsts<'tcx> {
660
680
}
661
681
662
682
impl < ' tcx > UpvarSubsts < ' tcx > {
683
+ /// Returns an iterator over the list of types of captured paths by the closure/generator.
684
+ /// In case there was a type error in figuring out the types of the captured path, an
685
+ /// empty iterator is returned.
663
686
#[ inline]
664
687
pub fn upvar_tys ( self ) -> impl Iterator < Item = Ty < ' tcx > > + ' tcx {
665
- let tupled_upvars_ty = match self {
666
- UpvarSubsts :: Closure ( substs) => substs. as_closure ( ) . split ( ) . tupled_upvars_ty ,
667
- UpvarSubsts :: Generator ( substs) => substs. as_generator ( ) . split ( ) . tupled_upvars_ty ,
688
+ let tupled_tys = match self {
689
+ UpvarSubsts :: Closure ( substs) => substs. as_closure ( ) . tupled_upvars_ty ( ) ,
690
+ UpvarSubsts :: Generator ( substs) => substs. as_generator ( ) . tupled_upvars_ty ( ) ,
668
691
} ;
669
- tupled_upvars_ty. expect_ty ( ) . tuple_fields ( )
692
+
693
+ match tupled_tys. kind ( ) {
694
+ TyKind :: Error ( _) => None ,
695
+ TyKind :: Tuple ( ..) => Some ( self . tupled_upvars_ty ( ) . tuple_fields ( ) ) ,
696
+ TyKind :: Infer ( _) => bug ! ( "upvar_tys called before capture types are inferred" ) ,
697
+ ty => bug ! ( "Unexpected representation of upvar types tuple {:?}" , ty) ,
698
+ }
699
+ . into_iter ( )
700
+ . flatten ( )
670
701
}
671
702
672
703
#[ inline]
0 commit comments