pub trait TypeFolder<'tcx>: Sized {
    type Error = !;
    fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;

    fn fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Binder<'tcx, T>
    where
        T: TypeFoldable<'tcx>,
        Self: TypeFolder<'tcx, Error = !>
, { ... }
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx>
    where
        Self: TypeFolder<'tcx, Error = !>
, { ... }
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx>
    where
        Self: TypeFolder<'tcx, Error = !>
, { ... }
fn fold_const(&mut self, c: &'tcx Const<'tcx>) -> &'tcx Const<'tcx>
    where
        Self: TypeFolder<'tcx, Error = !>
, { ... }
fn fold_predicate(&mut self, p: Predicate<'tcx>) -> Predicate<'tcx>
    where
        Self: TypeFolder<'tcx, Error = !>
, { ... }
fn fold_mir_const(&mut self, c: ConstantKind<'tcx>) -> ConstantKind<'tcx>
    where
        Self: TypeFolder<'tcx, Error = !>
, { ... } }
Expand description

The TypeFolder trait defines the actual folding. There is a method defined for every foldable type. Each of these has a default implementation that does an “identity” fold. Within each identity fold, it should invoke foo.fold_with(self) to fold each sub-item.

If this folder is fallible (and therefore its Error associated type is something other than the default, never), FallibleTypeFolder should be implemented manually; otherwise, a blanket implementation of FallibleTypeFolder will defer to the infallible methods of this trait to ensure that the two APIs are coherent.

Associated Types

Required methods

Provided methods

Implementors