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.

Implementations on Foreign Types§

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> 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, T: TypeFoldable<I>> TypeFoldable<I> for Lrc<T>

source§

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

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, 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> 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, T: TypeFoldable<I>, U: TypeFoldable<I>> TypeFoldable<I> for (T, U)

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> 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, 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>, 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> 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, A: TypeFoldable<I>, B: TypeFoldable<I>, C: TypeFoldable<I>> TypeFoldable<I> for (A, B, C)

Implementors§