# Trait rustc_type_ir::fold::TypeFoldable

source ·

    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§

source

#### 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§

source

#### 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`.

## Object Safety§

This trait is not object safe.

## Implementations on Foreign Types§

source§

### impl<I: Interner> TypeFoldable<I> for Movability

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for Mutability

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for bool

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for u16

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for u32

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for u64

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for ()

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for usize

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### fn fold_with<F: TypeFolder<I>>(self, _: &mut F) -> Self

source§

### impl<I: Interner> TypeFoldable<I> for String

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, _: &mut F, ) -> Result<Self, F::Error>

source§

#### 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)

source§

#### 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>

source§

#### 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]>

source§

#### 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>

source§

#### 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>

source§

#### 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>

source§

#### 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>

source§

#### 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)

source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<(T, U), F::Error>

## Implementors§

source§

### impl<I> TypeFoldable<I> for CanonicalTyVarKind
where I: Interner,

source§

### impl<I> TypeFoldable<I> for CanonicalVarKind<I>
where I: Interner, I::PlaceholderTy: TypeFoldable<I>, I::PlaceholderRegion: TypeFoldable<I>, I::PlaceholderConst: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for ExistentialPredicate<I>
where I: Interner, ExistentialTraitRef<I>: TypeFoldable<I>, ExistentialProjection<I>: TypeFoldable<I>, I::DefId: TypeFoldable<I>,

source§

### 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>,

source§

### 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>,

source§

### impl<I> TypeFoldable<I> for ProbeKind<I>
where I: Interner, QueryResult<I>: TypeFoldable<I>, CandidateSource<I>: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for CanonicalVarInfo<I>
where I: Interner, CanonicalVarKind<I>: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for CanonicalVarValues<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for UnevaluatedConst<I>
where I: Interner, I::DefId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for OpaqueTypeKey<I>
where I: Interner, I::LocalDefId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for AliasTerm<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>, I::DefId: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for CoercePredicate<I>
where I: Interner, I::Ty: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for ExistentialProjection<I>
where I: Interner, I::DefId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>, I::Term: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for ExistentialTraitRef<I>
where I: Interner, I::DefId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for NormalizesTo<I>
where I: Interner, AliasTerm<I>: TypeFoldable<I>, I::Term: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for ProjectionPredicate<I>
where I: Interner, AliasTerm<I>: TypeFoldable<I>, I::Term: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for SubtypePredicate<I>
where I: Interner, I::Ty: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for TraitPredicate<I>
where I: Interner, TraitRef<I>: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for TraitRef<I>
where I: Interner, I::DefId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

source§

### 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>,

source§

### impl<I> TypeFoldable<I> for NestedNormalizationGoals<I>
where I: Interner, Vec<(GoalSource, Goal<I, I::Predicate>)>: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for PredefinedOpaquesData<I>
where I: Interner, Vec<(OpaqueTypeKey<I>, I::Ty)>: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for Response<I>
where I: Interner, CanonicalVarValues<I>: TypeFoldable<I>, I::ExternalConstraints: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for ClosureArgs<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for CoroutineArgs<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for CoroutineClosureArgs<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for CoroutineClosureSignature<I>
where I: Interner, I::Ty: TypeFoldable<I>, I::Safety: TypeFoldable<I>, I::Abi: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for GenSig<I>
where I: Interner, I::Ty: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for AliasTy<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>, I::DefId: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for FnSig<I>
where I: Interner, I::Tys: TypeFoldable<I>, I::Safety: TypeFoldable<I>, I::Abi: TypeFoldable<I>,

source§

### impl<I> TypeFoldable<I> for TypeAndMut<I>
where I: Interner, I::Ty: TypeFoldable<I>,

source§

### impl<I, A> TypeFoldable<I> for OutlivesPredicate<I, A>
where I: Interner, A: TypeFoldable<I>, I::Region: TypeFoldable<I>,

source§

### impl<I, P> TypeFoldable<I> for Goal<I, P>
where I: Interner, I::ParamEnv: TypeFoldable<I>, P: TypeFoldable<I>,

source§

### impl<I, P> TypeFoldable<I> for QueryInput<I, P>
where I: Interner, Goal<I, P>: TypeFoldable<I>, I::PredefinedOpaques: TypeFoldable<I>,

source§

### impl<I, T> TypeFoldable<I> for State<I, T>
where I: Interner, CanonicalVarValues<I>: TypeFoldable<I>, T: TypeFoldable<I>,

source§

### impl<I, V> TypeFoldable<I> for Canonical<I, V>
where I: Interner, V: TypeFoldable<I>, I::DefiningOpaqueTypes: TypeFoldable<I>, I::CanonicalVars: TypeFoldable<I>,

source§

### impl<I: Interner> TypeFoldable<I> for Variance

source§

### impl<I: Interner> TypeFoldable<I> for BoundConstness

source§

### impl<I: Interner> TypeFoldable<I> for PredicatePolarity

source§

### impl<I: Interner> TypeFoldable<I> for AliasRelationDirection

source§

### impl<I: Interner> TypeFoldable<I> for BuiltinImplSource

source§

### impl<I: Interner> TypeFoldable<I> for Certainty

source§

### impl<I: Interner> TypeFoldable<I> for GoalSource

source§

### impl<I: Interner> TypeFoldable<I> for MaybeCause

source§

### impl<I: Interner> TypeFoldable<I> for AliasTyKind

source§

### impl<I: Interner> TypeFoldable<I> for FloatTy

source§

### impl<I: Interner> TypeFoldable<I> for InferTy

source§

### impl<I: Interner> TypeFoldable<I> for IntVarValue

source§

### impl<I: Interner> TypeFoldable<I> for RegionVid

source§

### impl<I: Interner> TypeFoldable<I> for NoSolution

source§

### impl<I: Interner> TypeFoldable<I> for DebruijnIndex

source§

### impl<I: Interner> TypeFoldable<I> for UniverseIndex

source§

### impl<I: Interner, T> !TypeFoldable<I> for EarlyBinder<I, T>

For early binders, you should first call `instantiate` before using any visitors.

source§

### impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T>

source§

### impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Lrc<T>

source§

### impl<T, I> TypeFoldable<I> for ExpectedFound<T>
where I: Interner, T: TypeFoldable<I>,