Merge all TypeVisitable for &List<T>
impls into one generic one
This commit is contained in:
parent
9d9306828c
commit
c6fcb1c6a3
4 changed files with 13 additions and 41 deletions
|
@ -44,6 +44,15 @@ pub struct Canonical<'tcx, V> {
|
||||||
|
|
||||||
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
|
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
|
||||||
|
|
||||||
|
impl<'tcx> ty::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> {
|
||||||
|
fn try_fold_with<F: ty::FallibleTypeFolder<'tcx>>(
|
||||||
|
self,
|
||||||
|
folder: &mut F,
|
||||||
|
) -> Result<Self, F::Error> {
|
||||||
|
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_canonical_var_infos(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A set of values corresponding to the canonical variables from some
|
/// A set of values corresponding to the canonical variables from some
|
||||||
/// `Canonical`. You can give these values to
|
/// `Canonical`. You can give these values to
|
||||||
/// `canonical_value.substitute` to substitute them into the canonical
|
/// `canonical_value.substitute` to substitute them into the canonical
|
||||||
|
@ -90,6 +99,7 @@ impl<'tcx> Default for OriginalQueryValues<'tcx> {
|
||||||
/// a copy of the canonical value in some other inference context,
|
/// a copy of the canonical value in some other inference context,
|
||||||
/// with fresh inference variables replacing the canonical values.
|
/// with fresh inference variables replacing the canonical values.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
|
||||||
|
#[derive(TypeFoldable, TypeVisitable)]
|
||||||
pub struct CanonicalVarInfo<'tcx> {
|
pub struct CanonicalVarInfo<'tcx> {
|
||||||
pub kind: CanonicalVarKind<'tcx>,
|
pub kind: CanonicalVarKind<'tcx>,
|
||||||
}
|
}
|
||||||
|
@ -115,6 +125,7 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
|
||||||
/// in the type-theory sense of the term -- i.e., a "meta" type system
|
/// in the type-theory sense of the term -- i.e., a "meta" type system
|
||||||
/// that analyzes type-like values.
|
/// that analyzes type-like values.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
|
||||||
|
#[derive(TypeFoldable, TypeVisitable)]
|
||||||
pub enum CanonicalVarKind<'tcx> {
|
pub enum CanonicalVarKind<'tcx> {
|
||||||
/// Some kind of type inference variable.
|
/// Some kind of type inference variable.
|
||||||
Ty(CanonicalTyVarKind),
|
Ty(CanonicalTyVarKind),
|
||||||
|
@ -299,14 +310,7 @@ pub type QueryOutlivesConstraint<'tcx> = (
|
||||||
TrivialTypeTraversalAndLiftImpls! {
|
TrivialTypeTraversalAndLiftImpls! {
|
||||||
for <'tcx> {
|
for <'tcx> {
|
||||||
crate::infer::canonical::Certainty,
|
crate::infer::canonical::Certainty,
|
||||||
crate::infer::canonical::CanonicalVarInfo<'tcx>,
|
crate::infer::canonical::CanonicalTyVarKind,
|
||||||
crate::infer::canonical::CanonicalVarKind<'tcx>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TrivialTypeTraversalImpls! {
|
|
||||||
for <'tcx> {
|
|
||||||
crate::infer::canonical::CanonicalVarInfos<'tcx>,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
//! `TypeVisitable` implementations for MIR types
|
//! `TypeVisitable` implementations for MIR types
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::ty;
|
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
|
impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
|
|
|
@ -602,26 +602,12 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Binder<'tcx, ty::Existentia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx>
|
|
||||||
for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>
|
|
||||||
{
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
self.iter().try_for_each(|p| p.visit_with(visitor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
|
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<ProjectionKind> {
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
folder.try_fold_ty(self)
|
folder.try_fold_ty(self)
|
||||||
|
@ -797,12 +783,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
self.iter().try_for_each(|p| p.visit_with(visitor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
|
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
self.try_map_id(|x| x.try_fold_with(folder))
|
self.try_map_id(|x| x.try_fold_with(folder))
|
||||||
|
|
|
@ -459,12 +459,6 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for SubstsRef<'tcx> {
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
// This code is fairly hot, though not as hot as `SubstsRef`.
|
// 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>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
|
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for &'tcx ty::List<T> {
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
self.iter().try_for_each(|t| t.visit_with(visitor))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue