pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {
// Required method
fn try_fold_with<F: FallibleTypeFolder<I>>(
self,
folder: &mut F,
) -> Result<Self, F::Error>;
// Provided method
fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self { ... }
}
Expand description
This trait is implemented for every type that can be folded, providing the skeleton of the traversal.
To implement this conveniently, use the derive macro located in
rustc_macros
.
This trait is a sub-trait of TypeVisitable
. This is because many
TypeFolder
instances use the methods in TypeVisitableExt
while folding,
which means in practice almost every foldable type needs to also be
visitable. (However, there are some types that are visitable without being
foldable.)
Required Methods§
Sourcefn try_fold_with<F: FallibleTypeFolder<I>>(
self,
folder: &mut F,
) -> Result<Self, F::Error>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
The entry point for folding. To fold a value t
with a folder f
call: t.try_fold_with(f)
.
For most types, this just traverses the value, calling try_fold_with
on each field/element.
For types of interest (such as Ty
), the implementation of this method
calls a folder method specifically for that type (such as
F::try_fold_ty
). This is where control transfers from TypeFoldable
to TypeFolder
.
Provided Methods§
Sourcefn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self
fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self
A convenient alternative to try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<I: Interner> TypeFoldable<I> for bool
impl<I: Interner> TypeFoldable<I> for bool
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for u16
impl<I: Interner> TypeFoldable<I> for u16
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for u32
impl<I: Interner> TypeFoldable<I> for u32
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for u64
impl<I: Interner> TypeFoldable<I> for u64
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for ()
impl<I: Interner> TypeFoldable<I> for ()
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for usize
impl<I: Interner> TypeFoldable<I> for usize
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for String
impl<I: Interner> TypeFoldable<I> for String
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for Movability
impl<I: Interner> TypeFoldable<I> for Movability
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner> TypeFoldable<I> for Mutability
impl<I: Interner> TypeFoldable<I> for Mutability
fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self
Source§impl<I: Interner, A: TypeFoldable<I>, B: TypeFoldable<I>, C: TypeFoldable<I>> TypeFoldable<I> for (A, B, C)
impl<I: Interner, A: TypeFoldable<I>, B: TypeFoldable<I>, C: TypeFoldable<I>> TypeFoldable<I> for (A, B, C)
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<(A, B, C), F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Option<T>
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Option<T>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Box<[T]>
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Box<[T]>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Box<T>
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Box<T>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Vec<T>
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Vec<T>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for ThinVec<T>
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for ThinVec<T>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>, E: TypeFoldable<I>> TypeFoldable<I> for Result<T, E>
impl<I: Interner, T: TypeFoldable<I>, E: TypeFoldable<I>> TypeFoldable<I> for Result<T, E>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>, Ix: Idx> TypeFoldable<I> for IndexVec<Ix, T>
impl<I: Interner, T: TypeFoldable<I>, Ix: Idx> TypeFoldable<I> for IndexVec<Ix, T>
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<Self, F::Error>
Source§impl<I: Interner, T: TypeFoldable<I>, U: TypeFoldable<I>> TypeFoldable<I> for (T, U)
impl<I: Interner, T: TypeFoldable<I>, U: TypeFoldable<I>> TypeFoldable<I> for (T, U)
fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<(T, U), F::Error>
Implementors§
impl<I> TypeFoldable<I> for CanonicalTyVarKindwhere
I: Interner,
impl<I> TypeFoldable<I> for CanonicalVarKind<I>where
I: Interner,
I::PlaceholderTy: TypeFoldable<I>,
I::PlaceholderRegion: TypeFoldable<I>,
I::PlaceholderConst: TypeFoldable<I>,
impl<I> TypeFoldable<I> for ExistentialPredicate<I>where
I: Interner,
ExistentialTraitRef<I>: TypeFoldable<I>,
ExistentialProjection<I>: TypeFoldable<I>,
I::DefId: TypeFoldable<I>,
impl<I> TypeFoldable<I> for ClauseKind<I>where
I: Interner,
TraitPredicate<I>: TypeFoldable<I>,
OutlivesPredicate<I, I::Region>: TypeFoldable<I>,
OutlivesPredicate<I, I::Ty>: TypeFoldable<I>,
ProjectionPredicate<I>: TypeFoldable<I>,
I::Const: TypeFoldable<I>,
I::Ty: TypeFoldable<I>,
I::GenericArg: TypeFoldable<I>,
HostEffectPredicate<I>: TypeFoldable<I>,
impl<I> TypeFoldable<I> for PredicateKind<I>where
I: Interner,
ClauseKind<I>: TypeFoldable<I>,
I::DefId: TypeFoldable<I>,
SubtypePredicate<I>: TypeFoldable<I>,
CoercePredicate<I>: TypeFoldable<I>,
I::Const: TypeFoldable<I>,
NormalizesTo<I>: TypeFoldable<I>,
I::Term: TypeFoldable<I>,
impl<I> TypeFoldable<I> for ProbeKind<I>
impl<I> TypeFoldable<I> for CanonicalVarInfo<I>
impl<I> TypeFoldable<I> for CanonicalVarValues<I>
impl<I> TypeFoldable<I> for UnevaluatedConst<I>
impl<I> TypeFoldable<I> for OpaqueTypeKey<I>
impl<I> TypeFoldable<I> for AliasTerm<I>
impl<I> TypeFoldable<I> for CoercePredicate<I>
impl<I> TypeFoldable<I> for ExistentialProjection<I>where
I: Interner,
I::DefId: TypeFoldable<I>,
I::GenericArgs: TypeFoldable<I>,
I::Term: TypeFoldable<I>,
impl<I> TypeFoldable<I> for ExistentialTraitRef<I>
impl<I> TypeFoldable<I> for HostEffectPredicate<I>
impl<I> TypeFoldable<I> for NormalizesTo<I>
impl<I> TypeFoldable<I> for ProjectionPredicate<I>
impl<I> TypeFoldable<I> for SubtypePredicate<I>
impl<I> TypeFoldable<I> for TraitPredicate<I>
impl<I> TypeFoldable<I> for TraitRef<I>
impl<I> TypeFoldable<I> for ExternalConstraintsData<I>where
I: Interner,
Vec<OutlivesPredicate<I, I::GenericArg>>: TypeFoldable<I>,
Vec<(OpaqueTypeKey<I>, I::Ty)>: TypeFoldable<I>,
NestedNormalizationGoals<I>: TypeFoldable<I>,
impl<I> TypeFoldable<I> for NestedNormalizationGoals<I>
impl<I> TypeFoldable<I> for PredefinedOpaquesData<I>
impl<I> TypeFoldable<I> for Response<I>
impl<I> TypeFoldable<I> for ClosureArgs<I>
impl<I> TypeFoldable<I> for CoroutineArgs<I>
impl<I> TypeFoldable<I> for CoroutineClosureArgs<I>
impl<I> TypeFoldable<I> for CoroutineClosureSignature<I>
impl<I> TypeFoldable<I> for GenSig<I>
impl<I> TypeFoldable<I> for AliasTy<I>
impl<I> TypeFoldable<I> for FnHeader<I>
impl<I> TypeFoldable<I> for FnSig<I>
impl<I> TypeFoldable<I> for FnSigTys<I>
impl<I> TypeFoldable<I> for TypeAndMut<I>
impl<I, A> TypeFoldable<I> for OutlivesPredicate<I, A>
impl<I, P> TypeFoldable<I> for Goal<I, P>
impl<I, P> TypeFoldable<I> for QueryInput<I, P>
impl<I, T> TypeFoldable<I> for State<I, T>
impl<I, V> TypeFoldable<I> for Canonical<I, V>
impl<I: Interner> TypeFoldable<I> for Variance
impl<I: Interner> TypeFoldable<I> for BoundConstness
impl<I: Interner> TypeFoldable<I> for PredicatePolarity
impl<I: Interner> TypeFoldable<I> for AliasRelationDirection
impl<I: Interner> TypeFoldable<I> for BuiltinImplSource
impl<I: Interner> TypeFoldable<I> for Certainty
impl<I: Interner> TypeFoldable<I> for GoalSource
impl<I: Interner> TypeFoldable<I> for MaybeCause
impl<I: Interner> TypeFoldable<I> for AliasTyKind
impl<I: Interner> TypeFoldable<I> for FloatTy
impl<I: Interner> TypeFoldable<I> for InferTy
impl<I: Interner> TypeFoldable<I> for IntVarValue
impl<I: Interner> TypeFoldable<I> for RegionVid
impl<I: Interner> TypeFoldable<I> for NoSolution
impl<I: Interner> TypeFoldable<I> for DebruijnIndex
impl<I: Interner> TypeFoldable<I> for UniverseIndex
impl<I: Interner, T> !TypeFoldable<I> for EarlyBinder<I, T>
For early binders, you should first call instantiate
before using any visitors.