Skip to content

Commit fbab69c

Browse files
committed
Get rid of subst_bound_vars uses
1 parent e28f0c9 commit fbab69c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

crates/hir_ty/src/infer/unify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<T> Canonicalized<T> {
152152
// eagerly replace projections in the type; we may be getting types
153153
// e.g. from where clauses where this hasn't happened yet
154154
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),
156156
);
157157
ctx.table.unify(&TyKind::InferenceVar(v, k).intern(&Interner), &ty);
158158
}
@@ -173,8 +173,8 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substitution> {
173173
// fallback to Unknown in the end (kind of hacky, as below)
174174
.map(|_| table.new_type_var()),
175175
);
176-
let ty1_with_vars = tys.value.0.clone().subst_bound_vars(&vars);
177-
let ty2_with_vars = tys.value.1.clone().subst_bound_vars(&vars);
176+
let ty1_with_vars = vars.apply(tys.value.0.clone(), &Interner);
177+
let ty2_with_vars = vars.apply(tys.value.1.clone(), &Interner);
178178
if !table.unify(&ty1_with_vars, &ty2_with_vars) {
179179
return None;
180180
}

crates/hir_ty/src/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl<'a> TyLoweringContext<'a> {
477477
),
478478
);
479479
let s = generics.type_params_subst(self.db);
480-
t.substitution.clone().subst_bound_vars(&s)
480+
s.apply(t.substitution.clone(), &Interner)
481481
}
482482
TypeParamLoweringMode::Variable => t.substitution.clone(),
483483
};

crates/hir_ty/src/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use smallvec::SmallVec;
1212

1313
use crate::{
1414
AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId,
15-
InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, VariableKinds,
15+
InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKinds,
1616
};
1717

1818
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@@ -286,6 +286,10 @@ impl Substitution {
286286
Substitution(elements.into_iter().casted(interner).collect())
287287
}
288288

289+
pub fn apply<T: TypeWalk>(&self, value: T, _interner: &Interner) -> T {
290+
value.subst_bound_vars(self)
291+
}
292+
289293
// Temporary helper functions, to be removed
290294
pub fn intern(interned: SmallVec<[GenericArg; 2]>) -> Substitution {
291295
Substitution(interned)

0 commit comments

Comments
 (0)