From 351c29d859d74f7a61e654bdbcad634bfb136225 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 16 Nov 2019 12:53:13 +0100 Subject: 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. --- crates/ra_hir/src/ty/infer/unify.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir/src/ty/infer') 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 } impl Canonicalized { - pub fn decanonicalize_ty(&self, ty: Ty) -> Ty { - ty.fold(&mut |ty| match ty { - Ty::Bound(idx) => { - if (idx as usize) < self.free_vars.len() { - Ty::Infer(self.free_vars[idx as usize]) - } else { - Ty::Bound(idx) + pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { + ty.walk_mut_binders( + &mut |ty, binders| match ty { + &mut Ty::Bound(idx) => { + if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() { + *ty = Ty::Infer(self.free_vars[idx as usize - binders]); + } } - } - ty => ty, - }) + _ => {} + }, + 0, + ); + ty } pub fn apply_solution( -- cgit v1.2.3