Skip to content

Commit a163554

Browse files
committed
Fix Canonicalized::apply_solution
Now that we're using Chalk's `substitute` which actually knows about lifetimes, the hack doesn't work anymore, but we can put in a proper lifetime.
1 parent a838a60 commit a163554

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

crates/hir_ty/src/infer/unify.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
use std::borrow::Cow;
44

55
use chalk_ir::{
6-
fold::Fold, interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind,
6+
cast::Cast, fold::Fold, interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex,
7+
VariableKind,
78
};
89
use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
910

1011
use super::{DomainGoal, InferenceContext};
1112
use crate::{
12-
fold_tys, AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer,
13-
FnSubst, InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyExt, TyKind,
14-
TypeWalk, WhereClause,
13+
fold_tys, static_lifetime, AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds,
14+
DebruijnIndex, FnPointer, FnSubst, InEnvironment, InferenceVar, Interner, Scalar, Substitution,
15+
Ty, TyExt, TyKind, TypeWalk, WhereClause,
1516
};
1617

1718
impl<'a> InferenceContext<'a> {
@@ -139,15 +140,17 @@ impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
139140
let new_vars = Substitution::from_iter(
140141
&Interner,
141142
solution.binders.iter(&Interner).map(|k| match k.kind {
142-
VariableKind::Ty(TyVariableKind::General) => ctx.table.new_type_var(),
143-
VariableKind::Ty(TyVariableKind::Integer) => ctx.table.new_integer_var(),
144-
VariableKind::Ty(TyVariableKind::Float) => ctx.table.new_float_var(),
145-
// HACK: Chalk can sometimes return new lifetime variables. We
146-
// want to just skip them, but to not mess up the indices of
147-
// other variables, we'll just create a new type variable in
148-
// their place instead. This should not matter (we never see the
149-
// actual *uses* of the lifetime variable).
150-
VariableKind::Lifetime => ctx.table.new_type_var(),
143+
VariableKind::Ty(TyVariableKind::General) => {
144+
ctx.table.new_type_var().cast(&Interner)
145+
}
146+
VariableKind::Ty(TyVariableKind::Integer) => {
147+
ctx.table.new_integer_var().cast(&Interner)
148+
}
149+
VariableKind::Ty(TyVariableKind::Float) => {
150+
ctx.table.new_float_var().cast(&Interner)
151+
}
152+
// Chalk can sometimes return new lifetime variables. We just use the static lifetime everywhere
153+
VariableKind::Lifetime => static_lifetime().cast(&Interner),
151154
_ => panic!("const variable in solution"),
152155
}),
153156
);

0 commit comments

Comments
 (0)