From 69714d36e6617800f3edea174f5d6f76c985ad4c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 5 Apr 2021 17:13:50 +0200 Subject: Hide Binders internals more --- crates/hir_ty/src/walk.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/hir_ty/src/walk.rs') diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index 5dfd59746..b1e22da0a 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs @@ -139,7 +139,7 @@ impl TypeWalk for Ty { } } TyKind::Dyn(dyn_ty) => { - for p in dyn_ty.bounds.value.interned().iter() { + for p in dyn_ty.bounds.skip_binders().interned().iter() { p.walk(f); } } @@ -167,7 +167,7 @@ impl TypeWalk for Ty { p_ty.substitution.walk_mut_binders(f, binders); } TyKind::Dyn(dyn_ty) => { - for p in make_mut_slice(dyn_ty.bounds.value.interned_mut()) { + for p in make_mut_slice(dyn_ty.bounds.skip_binders_mut().interned_mut()) { p.walk_mut_binders(f, binders.shifted_in()); } } @@ -294,7 +294,7 @@ impl TypeWalk for Substitution { impl TypeWalk for Binders { fn walk(&self, f: &mut impl FnMut(&Ty)) { - self.value.walk(f); + self.skip_binders().walk(f); } fn walk_mut_binders( @@ -302,7 +302,7 @@ impl TypeWalk for Binders { f: &mut impl FnMut(&mut Ty, DebruijnIndex), binders: DebruijnIndex, ) { - self.value.walk_mut_binders(f, binders.shifted_in()) + self.skip_binders_mut().walk_mut_binders(f, binders.shifted_in()) } } -- cgit v1.2.3 From a316d583600e11ee1fcc8027a838efafe435f03c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 5 Apr 2021 19:15:13 +0200 Subject: Rename shift_bound_vars{_out} to align with Chalk --- crates/hir_ty/src/walk.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'crates/hir_ty/src/walk.rs') diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index b1e22da0a..b85e6ab4d 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs @@ -82,7 +82,7 @@ pub trait TypeWalk { *ty = substs.interned()[bound.index] .assert_ty_ref(&Interner) .clone() - .shift_bound_vars(binders); + .shifted_in_from(binders); } } }, @@ -92,7 +92,7 @@ pub trait TypeWalk { } /// Shifts up debruijn indices of `TyKind::Bound` vars by `n`. - fn shift_bound_vars(self, n: DebruijnIndex) -> Self + fn shifted_in_from(self, n: DebruijnIndex) -> Self where Self: Sized, { @@ -108,20 +108,22 @@ pub trait TypeWalk { } /// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`. - fn shift_bound_vars_out(self, n: DebruijnIndex) -> Self + fn shifted_out_to(self, n: DebruijnIndex) -> Option where Self: Sized + std::fmt::Debug, { - self.fold_binders( - &mut |ty, binders| match ty.kind(&Interner) { - TyKind::BoundVar(bound) if bound.debruijn >= binders => { - TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone())) - .intern(&Interner) + Some(self.fold_binders( + &mut |ty, binders| { + match ty.kind(&Interner) { + TyKind::BoundVar(bound) if bound.debruijn >= binders => { + TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone())) + .intern(&Interner) + } + _ => ty, } - _ => ty, }, DebruijnIndex::INNERMOST, - ) + )) } } -- cgit v1.2.3