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 +++--- crates/hir_ty/src/lower.rs | 2 +- crates/hir_ty/src/types.rs | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/hir_ty') 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; } diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index a3c3ef6b2..66e72c814 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -477,7 +477,7 @@ impl<'a> TyLoweringContext<'a> { ), ); let s = generics.type_params_subst(self.db); - t.substitution.clone().subst_bound_vars(&s) + s.apply(t.substitution.clone(), &Interner) } TypeParamLoweringMode::Variable => t.substitution.clone(), }; diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index 59678b45b..46c705a76 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs @@ -12,7 +12,7 @@ use smallvec::SmallVec; use crate::{ AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId, - InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, VariableKinds, + InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKinds, }; #[derive(Clone, PartialEq, Eq, Debug, Hash)] @@ -286,6 +286,10 @@ impl Substitution { Substitution(elements.into_iter().casted(interner).collect()) } + pub fn apply(&self, value: T, _interner: &Interner) -> T { + value.subst_bound_vars(self) + } + // Temporary helper functions, to be removed pub fn intern(interned: SmallVec<[GenericArg; 2]>) -> Substitution { Substitution(interned) -- cgit v1.2.3