diff options
Diffstat (limited to 'vendor/chalk-ir/src/fold/binder_impls.rs')
-rw-r--r-- | vendor/chalk-ir/src/fold/binder_impls.rs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/vendor/chalk-ir/src/fold/binder_impls.rs b/vendor/chalk-ir/src/fold/binder_impls.rs new file mode 100644 index 000000000..1f44c1629 --- /dev/null +++ b/vendor/chalk-ir/src/fold/binder_impls.rs @@ -0,0 +1,73 @@ +//! This module contains impls of `TypeFoldable` for those types that +//! introduce binders. +//! +//! The more interesting impls of `TypeFoldable` remain in the `fold` module. + +use crate::*; + +impl<I: Interner> TypeFoldable<I> for FnPointer<I> { + fn try_fold_with<E>( + self, + folder: &mut dyn FallibleTypeFolder<I, Error = E>, + outer_binder: DebruijnIndex, + ) -> Result<Self, E> { + let FnPointer { + num_binders, + substitution, + sig, + } = self; + Ok(FnPointer { + num_binders, + substitution: substitution.try_fold_with(folder, outer_binder.shifted_in())?, + sig: FnSig { + abi: sig.abi, + safety: sig.safety, + variadic: sig.variadic, + }, + }) + } +} + +impl<T, I: Interner> TypeFoldable<I> for Binders<T> +where + T: HasInterner<Interner = I> + TypeFoldable<I>, + I: Interner, +{ + fn try_fold_with<E>( + self, + folder: &mut dyn FallibleTypeFolder<I, Error = E>, + outer_binder: DebruijnIndex, + ) -> Result<Self, E> { + let Binders { + binders: self_binders, + value: self_value, + } = self; + let value = self_value.try_fold_with(folder, outer_binder.shifted_in())?; + let binders = VariableKinds { + interned: self_binders.interned().clone(), + }; + Ok(Binders::new(binders, value)) + } +} + +impl<I, T> TypeFoldable<I> for Canonical<T> +where + I: Interner, + T: HasInterner<Interner = I> + TypeFoldable<I>, +{ + fn try_fold_with<E>( + self, + folder: &mut dyn FallibleTypeFolder<I, Error = E>, + outer_binder: DebruijnIndex, + ) -> Result<Self, E> { + let Canonical { + binders: self_binders, + value: self_value, + } = self; + let value = self_value.try_fold_with(folder, outer_binder.shifted_in())?; + let binders = CanonicalVarKinds { + interned: self_binders.interned().clone(), + }; + Ok(Canonical { binders, value }) + } +} |