aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-08 12:32:48 +0100
committerFlorian Diebold <[email protected]>2021-04-08 13:08:55 +0100
commit0f058d61cea9805897702654bcca146fd0cdc507 (patch)
tree7a9709483d2b7eec78195e32a5e2d619ab9811f8 /crates/hir_ty/src/lib.rs
parentcaee3b6c2d9a7dbcf678cc06d0c1832a4bf19be4 (diff)
Replace remaining `fold` calls
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs27
1 files changed, 27 insertions, 0 deletions
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<T: HasInterner<Interner = Interner> + Fold<Interner
328 } 328 }
329 t.fold_with(&mut FreeVarFolder(f), DebruijnIndex::INNERMOST).expect("fold failed unexpectedly") 329 t.fold_with(&mut FreeVarFolder(f), DebruijnIndex::INNERMOST).expect("fold failed unexpectedly")
330} 330}
331
332pub(crate) fn fold_tys<T: HasInterner<Interner = Interner> + Fold<Interner>>(
333 t: T,
334 f: impl FnMut(Ty, DebruijnIndex) -> Ty,
335 binders: DebruijnIndex,
336) -> T::Result {
337 use chalk_ir::{
338 fold::{Folder, SuperFold},
339 Fallible,
340 };
341 struct TyFolder<F>(F);
342 impl<'i, F: FnMut(Ty, DebruijnIndex) -> Ty + 'i> Folder<'i, Interner> for TyFolder<F> {
343 fn as_dyn(&mut self) -> &mut dyn Folder<'i, Interner> {
344 self
345 }
346
347 fn interner(&self) -> &'i Interner {
348 &Interner
349 }
350
351 fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
352 let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
353 Ok(self.0(ty, outer_binder))
354 }
355 }
356 t.fold_with(&mut TyFolder(f), binders).expect("fold failed unexpectedly")
357}