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