diff options
author | Florian Diebold <[email protected]> | 2019-11-16 11:53:13 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-11-16 12:25:54 +0000 |
commit | 351c29d859d74f7a61e654bdbcad634bfb136225 (patch) | |
tree | 39289f3a5fd0d828780ffa3128317afc8a0598e4 /crates/ra_hir/src/ty/infer | |
parent | 9c2a9a9a0635e53466749fdedcdc5a371e658cde (diff) |
Fix handling of the binders in dyn/impl Trait
We need to be more careful now when substituting bound variables (previously, we
didn't have anything that used bound variables except Chalk, so it was not a
problem).
This is obviously quite ad-hoc; Chalk has more infrastructure for handling this
in a principled way, which we maybe should adopt.
Diffstat (limited to 'crates/ra_hir/src/ty/infer')
-rw-r--r-- | crates/ra_hir/src/ty/infer/unify.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs index ca33cc7f8..64d9394cf 100644 --- a/crates/ra_hir/src/ty/infer/unify.rs +++ b/crates/ra_hir/src/ty/infer/unify.rs | |||
@@ -134,17 +134,19 @@ where | |||
134 | } | 134 | } |
135 | 135 | ||
136 | impl<T> Canonicalized<T> { | 136 | impl<T> Canonicalized<T> { |
137 | pub fn decanonicalize_ty(&self, ty: Ty) -> Ty { | 137 | pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { |
138 | ty.fold(&mut |ty| match ty { | 138 | ty.walk_mut_binders( |
139 | Ty::Bound(idx) => { | 139 | &mut |ty, binders| match ty { |
140 | if (idx as usize) < self.free_vars.len() { | 140 | &mut Ty::Bound(idx) => { |
141 | Ty::Infer(self.free_vars[idx as usize]) | 141 | if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() { |
142 | } else { | 142 | *ty = Ty::Infer(self.free_vars[idx as usize - binders]); |
143 | Ty::Bound(idx) | 143 | } |
144 | } | 144 | } |
145 | } | 145 | _ => {} |
146 | ty => ty, | 146 | }, |
147 | }) | 147 | 0, |
148 | ); | ||
149 | ty | ||
148 | } | 150 | } |
149 | 151 | ||
150 | pub fn apply_solution( | 152 | pub fn apply_solution( |