Fix panic caused by #9966

Chalk can introduce new type variables when doing lazy normalization, so
we have to do the proper 'fudging' after all.
This commit is contained in:
Florian Diebold 2021-08-21 19:47:06 +02:00
parent 3f4c515223
commit df77e2448c
3 changed files with 129 additions and 17 deletions

View file

@ -985,20 +985,21 @@ impl<'a> InferenceContext<'a> {
inputs: Vec<Ty>,
) -> Vec<Ty> {
if let Some(expected_ty) = expected_output.to_option(&mut self.table) {
let snapshot = self.table.snapshot();
let result = if self.table.try_unify(&expected_ty, &output).is_ok() {
// FIXME: the unification could introduce lifetime variables, which we'd need to handle here
self.table.resolve_with_fallback(inputs, |var, kind, _, _| match kind {
chalk_ir::VariableKind::Ty(tk) => var.to_ty(&Interner, tk).cast(&Interner),
chalk_ir::VariableKind::Lifetime => var.to_lifetime(&Interner).cast(&Interner),
chalk_ir::VariableKind::Const(ty) => {
var.to_const(&Interner, ty).cast(&Interner)
}
})
} else {
Vec::new()
};
self.table.rollback_to(snapshot);
let result = self.table.fudge_inference(|table| {
if table.try_unify(&expected_ty, &output).is_ok() {
table.resolve_with_fallback(inputs, |var, kind, _, _| match kind {
chalk_ir::VariableKind::Ty(tk) => var.to_ty(&Interner, tk).cast(&Interner),
chalk_ir::VariableKind::Lifetime => {
var.to_lifetime(&Interner).cast(&Interner)
}
chalk_ir::VariableKind::Const(ty) => {
var.to_const(&Interner, ty).cast(&Interner)
}
})
} else {
Vec::new()
}
});
result
} else {
Vec::new()