|
5 | 5 | use self::InferTy::*;
|
6 | 6 | use self::TyKind::*;
|
7 | 7 |
|
8 |
| -use either::Either; |
9 |
| - |
10 | 8 | use crate::infer::canonical::Canonical;
|
11 | 9 | use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
|
12 | 10 | use crate::ty::{
|
@@ -396,11 +394,13 @@ impl<'tcx> ClosureSubsts<'tcx> {
|
396 | 394 | #[inline]
|
397 | 395 | pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
398 | 396 | match self.tupled_upvars_ty().kind() {
|
399 |
| - TyKind::Error(_) => Either::Left(std::iter::empty()), |
400 |
| - TyKind::Tuple(..) => Either::Right(self.tupled_upvars_ty().tuple_fields()), |
| 397 | + TyKind::Error(_) => None, |
| 398 | + TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()), |
401 | 399 | TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
|
402 | 400 | ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
|
403 | 401 | }
|
| 402 | + .into_iter() |
| 403 | + .flatten() |
404 | 404 | }
|
405 | 405 |
|
406 | 406 | /// Returns the tuple type representing the upvars for this closure.
|
@@ -531,11 +531,13 @@ impl<'tcx> GeneratorSubsts<'tcx> {
|
531 | 531 | #[inline]
|
532 | 532 | pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
533 | 533 | match self.tupled_upvars_ty().kind() {
|
534 |
| - TyKind::Error(_) => Either::Left(std::iter::empty()), |
535 |
| - TyKind::Tuple(..) => Either::Right(self.tupled_upvars_ty().tuple_fields()), |
| 534 | + TyKind::Error(_) => None, |
| 535 | + TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()), |
536 | 536 | TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
|
537 | 537 | ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
|
538 | 538 | }
|
| 539 | + .into_iter() |
| 540 | + .flatten() |
539 | 541 | }
|
540 | 542 |
|
541 | 543 | /// Returns the tuple type representing the upvars for this generator.
|
@@ -683,10 +685,19 @@ impl<'tcx> UpvarSubsts<'tcx> {
|
683 | 685 | /// empty iterator is returned.
|
684 | 686 | #[inline]
|
685 | 687 | pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
686 |
| - match self { |
687 |
| - UpvarSubsts::Closure(substs) => Either::Left(substs.as_closure().upvar_tys()), |
688 |
| - UpvarSubsts::Generator(substs) => Either::Right(substs.as_generator().upvar_tys()), |
| 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(), |
| 691 | + }; |
| 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), |
689 | 698 | }
|
| 699 | + .into_iter() |
| 700 | + .flatten() |
690 | 701 | }
|
691 | 702 |
|
692 | 703 | #[inline]
|
|
0 commit comments