diff options
author | Florian Diebold <[email protected]> | 2021-04-05 21:32:58 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-05 22:00:50 +0100 |
commit | 1ae967bf8e01262f1ace1c06f6670f09fcf92fd2 (patch) | |
tree | db440a2bdd6148bc292bd20397f389671f8cb48c /crates/hir_ty/src/walk.rs | |
parent | edc59d897d56815e8b9814cdc4ff084100e4f3b4 (diff) |
Fix shifting of binders in FnPointer
- don't shift in/out for Chalk mapping (we want to have the same
binders now)
- do shift in when creating the signature for a closure (though it
shouldn't matter much)
- do shift in when lowering a `fn()` type
- correctly deal with the implied binder in TypeWalk
Diffstat (limited to 'crates/hir_ty/src/walk.rs')
-rw-r--r-- | crates/hir_ty/src/walk.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index 963eb12c8..e1e77ba37 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs | |||
@@ -92,6 +92,13 @@ pub trait TypeWalk { | |||
92 | self | 92 | self |
93 | } | 93 | } |
94 | 94 | ||
95 | fn shifted_in(self, _interner: &Interner) -> Self | ||
96 | where | ||
97 | Self: Sized, | ||
98 | { | ||
99 | self.shifted_in_from(DebruijnIndex::ONE) | ||
100 | } | ||
101 | |||
95 | /// Shifts up debruijn indices of `TyKind::Bound` vars by `n`. | 102 | /// Shifts up debruijn indices of `TyKind::Bound` vars by `n`. |
96 | fn shifted_in_from(self, n: DebruijnIndex) -> Self | 103 | fn shifted_in_from(self, n: DebruijnIndex) -> Self |
97 | where | 104 | where |
@@ -149,6 +156,9 @@ impl TypeWalk for Ty { | |||
149 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => { | 156 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => { |
150 | ty.walk(f); | 157 | ty.walk(f); |
151 | } | 158 | } |
159 | TyKind::Function(fn_pointer) => { | ||
160 | fn_pointer.substitution.0.walk(f); | ||
161 | } | ||
152 | _ => { | 162 | _ => { |
153 | if let Some(substs) = self.substs() { | 163 | if let Some(substs) = self.substs() { |
154 | for t in substs.iter(&Interner) { | 164 | for t in substs.iter(&Interner) { |
@@ -180,6 +190,9 @@ impl TypeWalk for Ty { | |||
180 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => { | 190 | TyKind::Slice(ty) | TyKind::Array(ty) | TyKind::Ref(_, ty) | TyKind::Raw(_, ty) => { |
181 | ty.walk_mut_binders(f, binders); | 191 | ty.walk_mut_binders(f, binders); |
182 | } | 192 | } |
193 | TyKind::Function(fn_pointer) => { | ||
194 | fn_pointer.substitution.0.walk_mut_binders(f, binders.shifted_in()); | ||
195 | } | ||
183 | _ => { | 196 | _ => { |
184 | if let Some(substs) = self.substs_mut() { | 197 | if let Some(substs) = self.substs_mut() { |
185 | substs.walk_mut_binders(f, binders); | 198 | substs.walk_mut_binders(f, binders); |