aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/walk.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/walk.rs')
-rw-r--r--crates/hir_ty/src/walk.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs
index 5dfd59746..b85e6ab4d 100644
--- a/crates/hir_ty/src/walk.rs
+++ b/crates/hir_ty/src/walk.rs
@@ -82,7 +82,7 @@ pub trait TypeWalk {
82 *ty = substs.interned()[bound.index] 82 *ty = substs.interned()[bound.index]
83 .assert_ty_ref(&Interner) 83 .assert_ty_ref(&Interner)
84 .clone() 84 .clone()
85 .shift_bound_vars(binders); 85 .shifted_in_from(binders);
86 } 86 }
87 } 87 }
88 }, 88 },
@@ -92,7 +92,7 @@ pub trait TypeWalk {
92 } 92 }
93 93
94 /// Shifts up debruijn indices of `TyKind::Bound` vars by `n`. 94 /// Shifts up debruijn indices of `TyKind::Bound` vars by `n`.
95 fn shift_bound_vars(self, n: DebruijnIndex) -> Self 95 fn shifted_in_from(self, n: DebruijnIndex) -> Self
96 where 96 where
97 Self: Sized, 97 Self: Sized,
98 { 98 {
@@ -108,20 +108,22 @@ pub trait TypeWalk {
108 } 108 }
109 109
110 /// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`. 110 /// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`.
111 fn shift_bound_vars_out(self, n: DebruijnIndex) -> Self 111 fn shifted_out_to(self, n: DebruijnIndex) -> Option<Self>
112 where 112 where
113 Self: Sized + std::fmt::Debug, 113 Self: Sized + std::fmt::Debug,
114 { 114 {
115 self.fold_binders( 115 Some(self.fold_binders(
116 &mut |ty, binders| match ty.kind(&Interner) { 116 &mut |ty, binders| {
117 TyKind::BoundVar(bound) if bound.debruijn >= binders => { 117 match ty.kind(&Interner) {
118 TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone())) 118 TyKind::BoundVar(bound) if bound.debruijn >= binders => {
119 .intern(&Interner) 119 TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone()))
120 .intern(&Interner)
121 }
122 _ => ty,
120 } 123 }
121 _ => ty,
122 }, 124 },
123 DebruijnIndex::INNERMOST, 125 DebruijnIndex::INNERMOST,
124 ) 126 ))
125 } 127 }
126} 128}
127 129
@@ -139,7 +141,7 @@ impl TypeWalk for Ty {
139 } 141 }
140 } 142 }
141 TyKind::Dyn(dyn_ty) => { 143 TyKind::Dyn(dyn_ty) => {
142 for p in dyn_ty.bounds.value.interned().iter() { 144 for p in dyn_ty.bounds.skip_binders().interned().iter() {
143 p.walk(f); 145 p.walk(f);
144 } 146 }
145 } 147 }
@@ -167,7 +169,7 @@ impl TypeWalk for Ty {
167 p_ty.substitution.walk_mut_binders(f, binders); 169 p_ty.substitution.walk_mut_binders(f, binders);
168 } 170 }
169 TyKind::Dyn(dyn_ty) => { 171 TyKind::Dyn(dyn_ty) => {
170 for p in make_mut_slice(dyn_ty.bounds.value.interned_mut()) { 172 for p in make_mut_slice(dyn_ty.bounds.skip_binders_mut().interned_mut()) {
171 p.walk_mut_binders(f, binders.shifted_in()); 173 p.walk_mut_binders(f, binders.shifted_in());
172 } 174 }
173 } 175 }
@@ -294,7 +296,7 @@ impl TypeWalk for Substitution {
294 296
295impl<T: TypeWalk> TypeWalk for Binders<T> { 297impl<T: TypeWalk> TypeWalk for Binders<T> {
296 fn walk(&self, f: &mut impl FnMut(&Ty)) { 298 fn walk(&self, f: &mut impl FnMut(&Ty)) {
297 self.value.walk(f); 299 self.skip_binders().walk(f);
298 } 300 }
299 301
300 fn walk_mut_binders( 302 fn walk_mut_binders(
@@ -302,7 +304,7 @@ impl<T: TypeWalk> TypeWalk for Binders<T> {
302 f: &mut impl FnMut(&mut Ty, DebruijnIndex), 304 f: &mut impl FnMut(&mut Ty, DebruijnIndex),
303 binders: DebruijnIndex, 305 binders: DebruijnIndex,
304 ) { 306 ) {
305 self.value.walk_mut_binders(f, binders.shifted_in()) 307 self.skip_binders_mut().walk_mut_binders(f, binders.shifted_in())
306 } 308 }
307} 309}
308 310