@@ -388,9 +388,19 @@ impl<'tcx> ClosureSubsts<'tcx> {
388388 self . split ( ) . parent_substs
389389 }
390390
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.
391394 #[ inline]
392395 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 ( )
394404 }
395405
396406 /// Returns the tuple type representing the upvars for this closure.
@@ -515,9 +525,19 @@ impl<'tcx> GeneratorSubsts<'tcx> {
515525 self . split ( ) . witness . expect_ty ( )
516526 }
517527
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.
518531 #[ inline]
519532 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 ( )
521541 }
522542
523543 /// Returns the tuple type representing the upvars for this generator.
@@ -660,13 +680,24 @@ pub enum UpvarSubsts<'tcx> {
660680}
661681
662682impl < ' 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.
663686 #[ inline]
664687 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 ( ) ,
668691 } ;
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 ( )
670701 }
671702
672703 #[ inline]
0 commit comments