From e28f0c98ba449c372ffcc450ac756f0adbdf9549 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 5 Apr 2021 18:54:31 +0200 Subject: Get rid of some walk_mut uses --- crates/hir_ty/src/infer/unify.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/infer/unify.rs') diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 8370f2e1c..06187df56 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -108,19 +108,22 @@ impl<'a, 'b> Canonicalizer<'a, 'b> { } impl Canonicalized { - pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { - ty.walk_mut_binders( + pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty { + ty.fold_binders( &mut |ty, binders| { - if let &mut TyKind::BoundVar(bound) = ty.interned_mut() { + if let TyKind::BoundVar(bound) = ty.kind(&Interner) { if bound.debruijn >= binders { let (v, k) = self.free_vars[bound.index]; - *ty = TyKind::InferenceVar(v, k).intern(&Interner); + TyKind::InferenceVar(v, k).intern(&Interner) + } else { + ty } + } else { + ty } }, DebruijnIndex::INNERMOST, - ); - ty + ) } pub(super) fn apply_solution( -- cgit v1.2.3 From fbab69cbffed37291b463c0e57fade49581e1de2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 5 Apr 2021 19:01:41 +0200 Subject: Get rid of subst_bound_vars uses --- crates/hir_ty/src/infer/unify.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/hir_ty/src/infer/unify.rs') diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 06187df56..c90a16720 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -152,7 +152,7 @@ impl Canonicalized { // eagerly replace projections in the type; we may be getting types // e.g. from where clauses where this hasn't happened yet let ty = ctx.normalize_associated_types_in( - ty.assert_ty_ref(&Interner).clone().subst_bound_vars(&new_vars), + new_vars.apply(ty.assert_ty_ref(&Interner).clone(), &Interner), ); ctx.table.unify(&TyKind::InferenceVar(v, k).intern(&Interner), &ty); } @@ -173,8 +173,8 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option { // fallback to Unknown in the end (kind of hacky, as below) .map(|_| table.new_type_var()), ); - let ty1_with_vars = tys.value.0.clone().subst_bound_vars(&vars); - let ty2_with_vars = tys.value.1.clone().subst_bound_vars(&vars); + let ty1_with_vars = vars.apply(tys.value.0.clone(), &Interner); + let ty2_with_vars = vars.apply(tys.value.1.clone(), &Interner); if !table.unify(&ty1_with_vars, &ty2_with_vars) { return None; } -- cgit v1.2.3