Skip to content

Commit c6fcb1c

Browse files
committed
Merge all TypeVisitable for &List<T> impls into one generic one
1 parent 9d93068 commit c6fcb1c

File tree

4 files changed

+13
-41
lines changed

4 files changed

+13
-41
lines changed

compiler/rustc_middle/src/infer/canonical.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ pub struct Canonical<'tcx, V> {
4444

4545
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
4646

47+
impl<'tcx> ty::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> {
48+
fn try_fold_with<F: ty::FallibleTypeFolder<'tcx>>(
49+
self,
50+
folder: &mut F,
51+
) -> Result<Self, F::Error> {
52+
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_canonical_var_infos(v))
53+
}
54+
}
55+
4756
/// A set of values corresponding to the canonical variables from some
4857
/// `Canonical`. You can give these values to
4958
/// `canonical_value.substitute` to substitute them into the canonical
@@ -90,6 +99,7 @@ impl<'tcx> Default for OriginalQueryValues<'tcx> {
9099
/// a copy of the canonical value in some other inference context,
91100
/// with fresh inference variables replacing the canonical values.
92101
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
102+
#[derive(TypeFoldable, TypeVisitable)]
93103
pub struct CanonicalVarInfo<'tcx> {
94104
pub kind: CanonicalVarKind<'tcx>,
95105
}
@@ -115,6 +125,7 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
115125
/// in the type-theory sense of the term -- i.e., a "meta" type system
116126
/// that analyzes type-like values.
117127
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
128+
#[derive(TypeFoldable, TypeVisitable)]
118129
pub enum CanonicalVarKind<'tcx> {
119130
/// Some kind of type inference variable.
120131
Ty(CanonicalTyVarKind),
@@ -299,14 +310,7 @@ pub type QueryOutlivesConstraint<'tcx> = (
299310
TrivialTypeTraversalAndLiftImpls! {
300311
for <'tcx> {
301312
crate::infer::canonical::Certainty,
302-
crate::infer::canonical::CanonicalVarInfo<'tcx>,
303-
crate::infer::canonical::CanonicalVarKind<'tcx>,
304-
}
305-
}
306-
307-
TrivialTypeTraversalImpls! {
308-
for <'tcx> {
309-
crate::infer::canonical::CanonicalVarInfos<'tcx>,
313+
crate::infer::canonical::CanonicalTyVarKind,
310314
}
311315
}
312316

compiler/rustc_middle/src/mir/type_visitable.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
//! `TypeVisitable` implementations for MIR types
22
33
use super::*;
4-
use crate::ty;
54

6-
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
7-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
8-
self.iter().try_for_each(|t| t.visit_with(visitor))
9-
}
10-
}
115
impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
126
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
137
ControlFlow::CONTINUE

compiler/rustc_middle/src/ty/structural_impls.rs

-20
Original file line numberDiff line numberDiff line change
@@ -602,26 +602,12 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Binder<'tcx, ty::Existentia
602602
}
603603
}
604604

605-
impl<'tcx> TypeVisitable<'tcx>
606-
for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>
607-
{
608-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
609-
self.iter().try_for_each(|p| p.visit_with(visitor))
610-
}
611-
}
612-
613605
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
614606
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
615607
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
616608
}
617609
}
618610

619-
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<ProjectionKind> {
620-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
621-
self.iter().try_for_each(|t| t.visit_with(visitor))
622-
}
623-
}
624-
625611
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
626612
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
627613
folder.try_fold_ty(self)
@@ -797,12 +783,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
797783
}
798784
}
799785

800-
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
801-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
802-
self.iter().try_for_each(|p| p.visit_with(visitor))
803-
}
804-
}
805-
806786
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
807787
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
808788
self.try_map_id(|x| x.try_fold_with(folder))

compiler/rustc_middle/src/ty/subst.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,6 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
459459
}
460460
}
461461

462-
impl<'tcx> TypeVisitable<'tcx> for SubstsRef<'tcx> {
463-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
464-
self.iter().try_for_each(|t| t.visit_with(visitor))
465-
}
466-
}
467-
468462
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
469463
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
470464
// This code is fairly hot, though not as hot as `SubstsRef`.
@@ -497,7 +491,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
497491
}
498492
}
499493

500-
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
494+
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for &'tcx ty::List<T> {
501495
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
502496
self.iter().try_for_each(|t| t.visit_with(visitor))
503497
}

0 commit comments

Comments
 (0)