aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/infer/unify.rs6
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/hir_ty/src/types.rs6
3 files changed, 9 insertions, 5 deletions
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<T> Canonicalized<T> {
152 // eagerly replace projections in the type; we may be getting types 152 // eagerly replace projections in the type; we may be getting types
153 // e.g. from where clauses where this hasn't happened yet 153 // e.g. from where clauses where this hasn't happened yet
154 let ty = ctx.normalize_associated_types_in( 154 let ty = ctx.normalize_associated_types_in(
155 ty.assert_ty_ref(&Interner).clone().subst_bound_vars(&new_vars), 155 new_vars.apply(ty.assert_ty_ref(&Interner).clone(), &Interner),
156 ); 156 );
157 ctx.table.unify(&TyKind::InferenceVar(v, k).intern(&Interner), &ty); 157 ctx.table.unify(&TyKind::InferenceVar(v, k).intern(&Interner), &ty);
158 } 158 }
@@ -173,8 +173,8 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substitution> {
173 // fallback to Unknown in the end (kind of hacky, as below) 173 // fallback to Unknown in the end (kind of hacky, as below)
174 .map(|_| table.new_type_var()), 174 .map(|_| table.new_type_var()),
175 ); 175 );
176 let ty1_with_vars = tys.value.0.clone().subst_bound_vars(&vars); 176 let ty1_with_vars = vars.apply(tys.value.0.clone(), &Interner);
177 let ty2_with_vars = tys.value.1.clone().subst_bound_vars(&vars); 177 let ty2_with_vars = vars.apply(tys.value.1.clone(), &Interner);
178 if !table.unify(&ty1_with_vars, &ty2_with_vars) { 178 if !table.unify(&ty1_with_vars, &ty2_with_vars) {
179 return None; 179 return None;
180 } 180 }
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> {
477 ), 477 ),
478 ); 478 );
479 let s = generics.type_params_subst(self.db); 479 let s = generics.type_params_subst(self.db);
480 t.substitution.clone().subst_bound_vars(&s) 480 s.apply(t.substitution.clone(), &Interner)
481 } 481 }
482 TypeParamLoweringMode::Variable => t.substitution.clone(), 482 TypeParamLoweringMode::Variable => t.substitution.clone(),
483 }; 483 };
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;
12 12
13use crate::{ 13use crate::{
14 AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId, 14 AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId,
15 InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, VariableKinds, 15 InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKinds,
16}; 16};
17 17
18#[derive(Clone, PartialEq, Eq, Debug, Hash)] 18#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@@ -286,6 +286,10 @@ impl Substitution {
286 Substitution(elements.into_iter().casted(interner).collect()) 286 Substitution(elements.into_iter().casted(interner).collect())
287 } 287 }
288 288
289 pub fn apply<T: TypeWalk>(&self, value: T, _interner: &Interner) -> T {
290 value.subst_bound_vars(self)
291 }
292
289 // Temporary helper functions, to be removed 293 // Temporary helper functions, to be removed
290 pub fn intern(interned: SmallVec<[GenericArg; 2]>) -> Substitution { 294 pub fn intern(interned: SmallVec<[GenericArg; 2]>) -> Substitution {
291 Substitution(interned) 295 Substitution(interned)