9975: minor: Fix panic caused by #9966 r=flodiebold a=flodiebold

Chalk can introduce new type variables when doing lazy normalization, so we have to do the proper 'fudging' after all.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2021-08-21 18:07:36 +00:00 committed by GitHub
commit 9e3517f8f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 129 additions and 17 deletions

View file

@ -986,20 +986,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()