From 0f058d61cea9805897702654bcca146fd0cdc507 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 8 Apr 2021 13:32:48 +0200 Subject: Replace remaining `fold` calls --- crates/hir_ty/src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'crates/hir_ty/src/lib.rs') diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 60680ec86..f7af8b8aa 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -328,3 +328,30 @@ pub(crate) fn fold_free_vars + Fold + Fold>( + t: T, + f: impl FnMut(Ty, DebruijnIndex) -> Ty, + binders: DebruijnIndex, +) -> T::Result { + use chalk_ir::{ + fold::{Folder, SuperFold}, + Fallible, + }; + struct TyFolder(F); + impl<'i, F: FnMut(Ty, DebruijnIndex) -> Ty + 'i> Folder<'i, Interner> for TyFolder { + fn as_dyn(&mut self) -> &mut dyn Folder<'i, Interner> { + self + } + + fn interner(&self) -> &'i Interner { + &Interner + } + + fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible { + let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?; + Ok(self.0(ty, outer_binder)) + } + } + t.fold_with(&mut TyFolder(f), binders).expect("fold failed unexpectedly") +} -- cgit v1.2.3