pub trait TypeFoldable<'tcx>: TypeVisitable<'tcx> {
    fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
        self,
        folder: &mut F
    ) -> Result<Self, F::Error>; fn fold_with<F: TypeFolder<'tcx>>(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.

Required Methods

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

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

Implementors

AdtDefs are basically the same as a DefId.

impl<'tcx> TypeFoldable<'tcx> for GenericKind<'tcx>

impl<'tcx> TypeFoldable<'tcx> for VerifyBound<'tcx>

impl<'tcx> TypeFoldable<'tcx> for VerifyIfEq<'tcx>

impl<'tcx> TypeFoldable<'tcx> for ValuePairs<'tcx>

impl<'tcx, T> TypeFoldable<'tcx> for Normalized<'tcx, T>where
    T: TypeFoldable<'tcx>,

impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Obligation<'tcx, O>

impl<'tcx> TypeFoldable<'tcx> for ImpliedOutlivesBounds<'tcx>

impl<'tcx> TypeFoldable<'tcx> for DropckOutlives<'tcx>

impl<'tcx> TypeFoldable<'tcx> for Types<'tcx>