diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-05 22:03:01 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-05 22:03:01 +0100 |
commit | 4bc8a018302d53951ae855ba57d07095a16ef182 (patch) | |
tree | db440a2bdd6148bc292bd20397f389671f8cb48c /crates/hir_ty/src/walk.rs | |
parent | 7ce0e9c9ca552e063855d60df7dca65ba9953fc3 (diff) | |
parent | 1ae967bf8e01262f1ace1c06f6670f09fcf92fd2 (diff) |
Merge #8360
8360: Fix shifting of binders in FnPointer r=flodiebold a=flodiebold
- 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
Tested with the binders validator on various repos, so I'm pretty sure this doesn't mess things up :grimacing:
Co-authored-by: Florian Diebold <[email protected]>
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); |