|
5 | 5 | use self::InferTy::*;
|
6 | 6 | use self::TyKind::*;
|
7 | 7 |
|
| 8 | +use either::Either; |
| 9 | + |
8 | 10 | use crate::infer::canonical::Canonical;
|
9 | 11 | use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
|
10 | 12 | use crate::ty::{
|
@@ -388,9 +390,17 @@ impl<'tcx> ClosureSubsts<'tcx> {
|
388 | 390 | self.split().parent_substs
|
389 | 391 | }
|
390 | 392 |
|
| 393 | + /// Returns an iterator over the list of types of captured paths by the closure. |
| 394 | + /// In case there was a type error in figuring out the types of the captured path, an |
| 395 | + /// empty iterator is returned. |
391 | 396 | #[inline]
|
392 | 397 | pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
393 |
| - self.tupled_upvars_ty().tuple_fields() |
| 398 | + 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()), |
| 401 | + TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"), |
| 402 | + ty => bug!("Unexpected representation of upvar types tuple {:?}", ty), |
| 403 | + } |
394 | 404 | }
|
395 | 405 |
|
396 | 406 | /// Returns the tuple type representing the upvars for this closure.
|
@@ -515,9 +525,17 @@ 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(_) => Either::Left(std::iter::empty()), |
| 535 | + TyKind::Tuple(..) => Either::Right(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 | + } |
521 | 539 | }
|
522 | 540 |
|
523 | 541 | /// Returns the tuple type representing the upvars for this generator.
|
@@ -660,13 +678,15 @@ pub enum UpvarSubsts<'tcx> {
|
660 | 678 | }
|
661 | 679 |
|
662 | 680 | impl<'tcx> UpvarSubsts<'tcx> {
|
| 681 | + /// Returns an iterator over the list of types of captured paths by the closure/generator. |
| 682 | + /// In case there was a type error in figuring out the types of the captured path, an |
| 683 | + /// empty iterator is returned. |
663 | 684 | #[inline]
|
664 | 685 | 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, |
668 |
| - }; |
669 |
| - tupled_upvars_ty.expect_ty().tuple_fields() |
| 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()), |
| 689 | + } |
670 | 690 | }
|
671 | 691 |
|
672 | 692 | #[inline]
|
|
0 commit comments