pub trait TypeFoldable<I>: TypeVisitable<I> + Clonewhere
I: Interner,{
// Required methods
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Self, <F as FallibleTypeFolder<I>>::Error>
where F: FallibleTypeFolder<I>;
fn fold_with<F>(self, folder: &mut F) -> Self
where F: TypeFolder<I>;
}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§
Sourcefn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Self, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Self, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
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 FallibleTypeFolder.
Sourcefn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
The entry point for folding. To fold a value t with a folder f
call: t.fold_with(f).
For most types, this just traverses the value, calling 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::fold_ty). This is where control transfers from TypeFoldable
to TypeFolder.
Same as TypeFoldable::try_fold_with, but not fallible. Make sure to keep
the behavior in sync across functions.
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<'tcx> TypeFoldable<TyCtxt<'tcx>> for InlineAsmTemplatePiece
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InlineAsmTemplatePiece
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for CoroutineKind
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for CoroutineKind
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for MatchSource
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for MatchSource
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for RangeEnd
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for RangeEnd
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InlineAsmRegOrRegClass
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InlineAsmRegOrRegClass
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for FieldIdx
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for FieldIdx
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for VariantIdx
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for VariantIdx
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InlineAsmOptions
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InlineAsmOptions
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for HirId
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for HirId
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for DefId
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for DefId
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for LocalDefId
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for LocalDefId
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Span
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Span
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ErrorGuaranteed
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ErrorGuaranteed
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _folder: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _folder: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Ident
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Ident
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Symbol
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Symbol
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, _: &mut F) -> Self
Source§impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Debug + Clone> TypeFoldable<TyCtxt<'tcx>> for Spanned<T>
impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Debug + Clone> TypeFoldable<TyCtxt<'tcx>> for Spanned<T>
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self
Source§impl<I> TypeFoldable<I> for boolwhere
I: Interner,
impl<I> TypeFoldable<I> for boolwhere
I: Interner,
fn try_fold_with<F>(
self,
_: &mut F,
) -> Result<bool, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, _: &mut F) -> boolwhere
F: TypeFolder<I>,
Source§impl<I> TypeFoldable<I> for u16where
I: Interner,
impl<I> TypeFoldable<I> for u16where
I: Interner,
fn try_fold_with<F>(
self,
_: &mut F,
) -> Result<u16, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, _: &mut F) -> u16where
F: TypeFolder<I>,
Source§impl<I> TypeFoldable<I> for u32where
I: Interner,
impl<I> TypeFoldable<I> for u32where
I: Interner,
fn try_fold_with<F>(
self,
_: &mut F,
) -> Result<u32, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, _: &mut F) -> u32where
F: TypeFolder<I>,
Source§impl<I> TypeFoldable<I> for u64where
I: Interner,
impl<I> TypeFoldable<I> for u64where
I: Interner,
fn try_fold_with<F>(
self,
_: &mut F,
) -> Result<u64, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, _: &mut F) -> u64where
F: TypeFolder<I>,
Source§impl<I> TypeFoldable<I> for ()where
I: Interner,
impl<I> TypeFoldable<I> for ()where
I: Interner,
fn try_fold_with<F>(
self,
_: &mut F,
) -> Result<(), <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, _: &mut F)where
F: TypeFolder<I>,
Source§impl<I> TypeFoldable<I> for usizewhere
I: Interner,
impl<I> TypeFoldable<I> for usizewhere
I: Interner,
fn try_fold_with<F>(
self,
_: &mut F,
) -> Result<usize, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, _: &mut F) -> usizewhere
F: TypeFolder<I>,
Source§impl<I, A, B, C> TypeFoldable<I> for (A, B, C)
impl<I, A, B, C> TypeFoldable<I> for (A, B, C)
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<(A, B, C), <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> (A, B, C)where
F: TypeFolder<I>,
Source§impl<I, T> TypeFoldable<I> for Option<T>where
I: Interner,
T: TypeFoldable<I>,
impl<I, T> TypeFoldable<I> for Option<T>where
I: Interner,
T: TypeFoldable<I>,
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Option<T>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Option<T>where
F: TypeFolder<I>,
Source§impl<I, T> TypeFoldable<I> for Box<[T]>where
I: Interner,
T: TypeFoldable<I>,
impl<I, T> TypeFoldable<I> for Box<[T]>where
I: Interner,
T: TypeFoldable<I>,
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Box<[T]>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Box<[T]>where
F: TypeFolder<I>,
Source§impl<I, T> TypeFoldable<I> for Box<T>where
I: Interner,
T: TypeFoldable<I>,
impl<I, T> TypeFoldable<I> for Box<T>where
I: Interner,
T: TypeFoldable<I>,
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Box<T>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Box<T>where
F: TypeFolder<I>,
Source§impl<I, T> TypeFoldable<I> for Arc<T>where
I: Interner,
T: TypeFoldable<I>,
impl<I, T> TypeFoldable<I> for Arc<T>where
I: Interner,
T: TypeFoldable<I>,
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Arc<T>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Arc<T>where
F: TypeFolder<I>,
Source§impl<I, T> TypeFoldable<I> for Vec<T>where
I: Interner,
T: TypeFoldable<I>,
impl<I, T> TypeFoldable<I> for Vec<T>where
I: Interner,
T: TypeFoldable<I>,
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Vec<T>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Vec<T>where
F: TypeFolder<I>,
Source§impl<I, T> TypeFoldable<I> for ThinVec<T>where
I: Interner,
T: TypeFoldable<I>,
impl<I, T> TypeFoldable<I> for ThinVec<T>where
I: Interner,
T: TypeFoldable<I>,
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<ThinVec<T>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> ThinVec<T>where
F: TypeFolder<I>,
Source§impl<I, T, E> TypeFoldable<I> for Result<T, E>
impl<I, T, E> TypeFoldable<I> for Result<T, E>
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<Result<T, E>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Result<T, E>where
F: TypeFolder<I>,
Source§impl<I, T, Ix> TypeFoldable<I> for IndexVec<Ix, T>
impl<I, T, Ix> TypeFoldable<I> for IndexVec<Ix, T>
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<IndexVec<Ix, T>, <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> IndexVec<Ix, T>where
F: TypeFolder<I>,
Source§impl<I, T, U> TypeFoldable<I> for (T, U)
impl<I, T, U> TypeFoldable<I> for (T, U)
fn try_fold_with<F>(
self,
folder: &mut F,
) -> Result<(T, U), <F as FallibleTypeFolder<I>>::Error>where
F: FallibleTypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> (T, U)where
F: TypeFolder<I>,
Implementors§
impl<I, T> !TypeFoldable<I> for EarlyBinder<I, T>where
I: Interner,
nightly only.For early binders, you should first call instantiate before using any visitors.