rustc_type_ir::fold

Trait 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.

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

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>> TypeFoldable<I> for ThinVec<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)

Implementors§

Source§

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

Source§

impl<I> TypeFoldable<I> for CanonicalVarKind<I>

Source§

impl<I> TypeFoldable<I> for ExistentialPredicate<I>

Source§

impl<I> TypeFoldable<I> for ClauseKind<I>

Source§

impl<I> TypeFoldable<I> for PredicateKind<I>

Source§

impl<I> TypeFoldable<I> for ProbeKind<I>

Source§

impl<I> TypeFoldable<I> for CanonicalVarInfo<I>

Source§

impl<I> TypeFoldable<I> for CanonicalVarValues<I>

Source§

impl<I> TypeFoldable<I> for UnevaluatedConst<I>

Source§

impl<I> TypeFoldable<I> for OpaqueTypeKey<I>

Source§

impl<I> TypeFoldable<I> for AliasTerm<I>

Source§

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

Source§

impl<I> TypeFoldable<I> for ExistentialProjection<I>

Source§

impl<I> TypeFoldable<I> for ExistentialTraitRef<I>

Source§

impl<I> TypeFoldable<I> for HostEffectPredicate<I>
where I: Interner, TraitRef<I>: 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>

Source§

impl<I> TypeFoldable<I> for ExternalConstraintsData<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>

Source§

impl<I> TypeFoldable<I> for ClosureArgs<I>

Source§

impl<I> TypeFoldable<I> for CoroutineArgs<I>

Source§

impl<I> TypeFoldable<I> for CoroutineClosureArgs<I>

Source§

impl<I> TypeFoldable<I> for CoroutineClosureSignature<I>
where I: Interner, I::Ty: 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>

Source§

impl<I> TypeFoldable<I> for FnHeader<I>
where I: Interner, I::Safety: TypeFoldable<I>, I::Abi: TypeFoldable<I>,

Source§

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

Source§

impl<I> TypeFoldable<I> for FnSigTys<I>
where I: Interner, I::Tys: 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>

Source§

impl<I, T> TypeFoldable<I> for State<I, T>

Source§

impl<I, V> TypeFoldable<I> for Canonical<I, V>

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