Skip to main content

## TypeFoldable

# Trait TypeFoldable

Source

    pub trait TypeFoldable<I: Interner>: TypeVisitable<I> + Clone {
        // Required methods
        fn try_fold_with<F: FallibleTypeFolder<I>>(
            self,
            folder: &mut F,
        ) -> Result<Self, F::Error>;
        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 `FallibleTypeFolder`.

Source

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

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

## Implementations on Foreign Types§

Source§

### impl<I: Interner, A: TypeFoldable<I>, B: TypeFoldable<I>, C: TypeFoldable<I>> TypeFoldable<I> for (A, B, C)

Source§

#### fn try_fold_with<F: FallibleTypeFolder<I>>( self, folder: &mut F, ) -> Result<(A, B, C), F::Error>

Source§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

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§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

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§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

Source§

### impl<I: Interner, T: TypeFoldable<I>, U: TypeFoldable<I>> TypeFoldable<I> for (T, U)

Source§

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

Source§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

Source§

### impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Arc<T>

Source§

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

Source§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

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§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

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§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &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§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self

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§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &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§

#### fn fold_with<F: TypeFolder<I>>(self, folder: &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 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 u8

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

## Implementors§

Source§

### impl<I, A> TypeFoldable<I> for OutlivesPredicate<I, A>
where I: Interner, A: TypeFoldable<I>, I::Region: TypeFoldable<I>,

Source§

### impl<I, K> TypeFoldable<I> for Alias<I, K>
where I: Interner, K: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

Source§

### impl<I, K> TypeFoldable<I> for NormalizesTo<I, K>
where I: Interner, K: TypeFoldable<I>, Alias<I, K>: TypeFoldable<I>, I::Term: TypeFoldable<I>,

Source§

### impl<I, P> TypeFoldable<I> for Goal<I, P>
where I: Interner, P: TypeFoldable<I>, I::ParamEnv: TypeFoldable<I>,

Source§

### impl<I, P> TypeFoldable<I> for QueryInput<I, P>
where I: Interner, P: TypeFoldable<I>, Goal<I, P>: TypeFoldable<I>, I::PredefinedOpaques: TypeFoldable<I>,

Source§

### impl<I, T> TypeFoldable<I> for Placeholder<I, T>
where I: Interner, T: TypeFoldable<I>,

Source§

### impl<I, T> TypeFoldable<I> for State<I, T>
where I: Interner, T: TypeFoldable<I>, CanonicalVarValues<I>: TypeFoldable<I>,

Source§

### impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T>

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> TypeFoldable<I> for BoundConstness

Source§

### impl<I: Interner> TypeFoldable<I> for BuiltinImplSource

Source§

### impl<I: Interner> TypeFoldable<I> for Certainty

Source§

### impl<I: Interner> TypeFoldable<I> for DebruijnIndex

Source§

### impl<I: Interner> TypeFoldable<I> for GoalSource

Source§

### impl<I: Interner> TypeFoldable<I> for Mutability

Source§

### impl<I: Interner> TypeFoldable<I> for PredicatePolarity

Source§

### impl<I: Interner> TypeFoldable<I> for rustc_type_ir::region_constraint::RegionConstraint<I>

Source§

### impl<I: Interner> TypeFoldable<I> for UniverseIndex

Source§

### impl<I: Interner> TypeFoldable<I> for Variance

Source§

### impl<I: Interner> TypeFoldable<I> for VisibleForLeakCheck

Source§

### impl<I> TypeFoldable<I> for AccessedOpaques<I>
where I: Interner, RerunCondition<I>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for AliasBoundKind
where I: Interner,

Source§

### impl<I> TypeFoldable<I> for AliasConstKind<I>
where I: Interner, I::TraitAssocConstId: TypeFoldable<I>, I::InherentAssocConstId: TypeFoldable<I>, I::FreeConstAliasId: TypeFoldable<I>, I::AnonConstId: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for AliasTermKind<I>
where I: Interner, I::TraitAssocTyId: TypeFoldable<I>, I::InherentAssocTyId: TypeFoldable<I>, I::OpaqueTyId: TypeFoldable<I>, I::FreeTyAliasId: TypeFoldable<I>, I::AnonConstId: TypeFoldable<I>, I::TraitAssocConstId: TypeFoldable<I>, I::FreeConstAliasId: TypeFoldable<I>, I::InherentAssocConstId: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for AliasTyKind<I>
where I: Interner, I::TraitAssocTyId: TypeFoldable<I>, I::InherentAssocTyId: TypeFoldable<I>, I::OpaqueTyId: TypeFoldable<I>, I::FreeTyAliasId: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for BoundVarIndexKind
where I: Interner,

Source§

### impl<I> TypeFoldable<I> for CanonicalVarValues<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ClauseKind<I>
where I: Interner, TraitPredicate<I>: TypeFoldable<I>, OutlivesPredicate<I, I::Region>: TypeFoldable<I>, OutlivesPredicate<I, I::Ty>: TypeFoldable<I>, ProjectionPredicate<I>: TypeFoldable<I>, I::Const: TypeFoldable<I>, I::Ty: TypeFoldable<I>, I::Term: TypeFoldable<I>, HostEffectPredicate<I>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ClosureArgs<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

Source§

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

Source§

### impl<I> TypeFoldable<I> for CoroutineArgs<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for CoroutineClosureArgs<I>
where I: Interner, I::GenericArgs: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for CoroutineClosureSignature<I>
where I: Interner, I::Ty: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for CoroutineWitnessTypes<I>
where I: Interner, I::Tys: TypeFoldable<I>, I::RegionAssumptions: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ExistentialPredicate<I>
where I: Interner, ExistentialTraitRef<I>: TypeFoldable<I>, ExistentialProjection<I>: TypeFoldable<I>, I::TraitId: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ExistentialProjection<I>
where I: Interner, I::TraitAssocTermId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>, I::Term: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ExistentialTraitRef<I>
where I: Interner, I::TraitId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ExternalConstraintsData<I>
where I: Interner, ExternalRegionConstraints<I>: TypeFoldable<I>, Vec<(OpaqueTypeKey<I>, I::Ty)>: TypeFoldable<I>, NestedNormalizationGoals<I>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ExternalRegionConstraints<I>
where I: Interner, Vec<(RegionConstraint<I>, VisibleForLeakCheck)>: TypeFoldable<I>, RegionConstraint<I>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for FnHeader<I>
where I: Interner,

Source§

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

Source§

### impl<I> TypeFoldable<I> for FnSigKind<I>
where I: Interner,

Source§

### impl<I> TypeFoldable<I> for FnSigTys<I>
where I: Interner, I::Tys: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for GenSig<I>
where I: Interner, I::Ty: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for HostEffectPredicate<I>
where I: Interner, TraitRef<I>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for IsRigid
where I: Interner,

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 OpaqueTypeKey<I>
where I: Interner, I::LocalOpaqueTyId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for PatternKind<I>
where I: Interner, I::Const: TypeFoldable<I>, I::PatList: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for PredicateKind<I>
where I: Interner, ClauseKind<I>: TypeFoldable<I>, I::TraitId: TypeFoldable<I>, SubtypePredicate<I>: TypeFoldable<I>, CoercePredicate<I>: TypeFoldable<I>, I::Const: TypeFoldable<I>, NormalizesTo<I>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ProbeKind<I>
where I: Interner, QueryResult<I>: TypeFoldable<I>, CandidateSource<I>: 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 rustc_type_ir::RegionConstraint<I>
where I: Interner, OutlivesPredicate<I, I::GenericArg>: TypeFoldable<I>, RegionEqPredicate<I>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for RegionEqPredicate<I>
where I: Interner, I::Region: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for RerunCondition<I>
where I: Interner, SmallCopyList<I::LocalDefId>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for Response<I>
where I: Interner, CanonicalVarValues<I>: TypeFoldable<I>, I::ExternalConstraints: 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>
where I: Interner, I::TraitId: TypeFoldable<I>, I::GenericArgs: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for TypeAndMut<I>
where I: Interner, I::Ty: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for UnsafeBinderInner<I>
where I: Interner, Binder<I, I::Ty>: TypeFoldable<I>,

Source§

### impl<I> TypeFoldable<I> for ValTreeKind<I>
where I: Interner, I::ScalarInt: TypeFoldable<I>, I::Consts: TypeFoldable<I>,

Source§

### impl<T, I> TypeFoldable<I> for ExpectedFound<T>
where I: Interner, T: TypeFoldable<I>,

Source§

### impl<T, I> TypeFoldable<I> for SmallCopyList<T>
where I: Interner, T: TypeFoldable<I> + Copy + Debug + Hash + Eq, [T; 1]: TypeFoldable<I>, [T; 2]: TypeFoldable<I>, [T; 3]: TypeFoldable<I>,