Skip to content

Commit 5229571

Browse files
committed
Address comments
1 parent f0ae24e commit 5229571

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3883,7 +3883,6 @@ version = "0.0.0"
38833883
dependencies = [
38843884
"bitflags",
38853885
"chalk-ir",
3886-
"either",
38873886
"measureme 9.0.0",
38883887
"polonius-engine",
38893888
"rustc-rayon-core",

compiler/rustc_middle/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ edition = "2018"
88
doctest = false
99

1010
[dependencies]
11-
either = "1.5.0"
1211
rustc_arena = { path = "../rustc_arena" }
1312
bitflags = "1.2.1"
1413
tracing = "0.1"

compiler/rustc_middle/src/ty/sty.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use self::InferTy::*;
66
use self::TyKind::*;
77

8-
use either::Either;
9-
108
use crate::infer::canonical::Canonical;
119
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
1210
use crate::ty::{
@@ -396,11 +394,13 @@ impl<'tcx> ClosureSubsts<'tcx> {
396394
#[inline]
397395
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
398396
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()),
401399
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
402400
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
403401
}
402+
.into_iter()
403+
.flatten()
404404
}
405405

406406
/// Returns the tuple type representing the upvars for this closure.
@@ -531,11 +531,13 @@ impl<'tcx> GeneratorSubsts<'tcx> {
531531
#[inline]
532532
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
533533
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()),
536536
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
537537
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
538538
}
539+
.into_iter()
540+
.flatten()
539541
}
540542

541543
/// Returns the tuple type representing the upvars for this generator.
@@ -683,10 +685,19 @@ impl<'tcx> UpvarSubsts<'tcx> {
683685
/// empty iterator is returned.
684686
#[inline]
685687
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),
689698
}
699+
.into_iter()
700+
.flatten()
690701
}
691702

692703
#[inline]

0 commit comments

Comments
 (0)