diff options
author | Florian Diebold <[email protected]> | 2021-04-07 20:26:37 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-08 13:08:55 +0100 |
commit | caee3b6c2d9a7dbcf678cc06d0c1832a4bf19be4 (patch) | |
tree | df770a02d0474c985cfb283c4386fb3711bae80f /crates/hir_ty/src/lib.rs | |
parent | b25b147e8604f62a5620a5833112e358ebeeb287 (diff) |
Replace some `fold` calls
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r-- | crates/hir_ty/src/lib.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 7d4793c2f..60680ec86 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -302,3 +302,29 @@ pub fn dummy_usize_const() -> Const { | |||
302 | } | 302 | } |
303 | .intern(&Interner) | 303 | .intern(&Interner) |
304 | } | 304 | } |
305 | |||
306 | pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + Fold<Interner>>( | ||
307 | t: T, | ||
308 | f: impl FnMut(BoundVar, DebruijnIndex) -> Ty, | ||
309 | ) -> T::Result { | ||
310 | use chalk_ir::{fold::Folder, Fallible}; | ||
311 | struct FreeVarFolder<F>(F); | ||
312 | impl<'i, F: FnMut(BoundVar, DebruijnIndex) -> Ty + 'i> Folder<'i, Interner> for FreeVarFolder<F> { | ||
313 | fn as_dyn(&mut self) -> &mut dyn Folder<'i, Interner> { | ||
314 | self | ||
315 | } | ||
316 | |||
317 | fn interner(&self) -> &'i Interner { | ||
318 | &Interner | ||
319 | } | ||
320 | |||
321 | fn fold_free_var_ty( | ||
322 | &mut self, | ||
323 | bound_var: BoundVar, | ||
324 | outer_binder: DebruijnIndex, | ||
325 | ) -> Fallible<Ty> { | ||
326 | Ok(self.0(bound_var, outer_binder)) | ||
327 | } | ||
328 | } | ||
329 | t.fold_with(&mut FreeVarFolder(f), DebruijnIndex::INNERMOST).expect("fold failed unexpectedly") | ||
330 | } | ||