1
Fork 0

fix an ICE when a valtree failed to evaluate

This commit is contained in:
Ralf Jung 2023-12-01 11:58:37 +01:00
parent 0919ad1838
commit 1d120e6169
3 changed files with 25 additions and 2 deletions

View file

@ -304,8 +304,16 @@ impl<'tcx> Const<'tcx> {
let (param_env, unevaluated) = unevaluated.prepare_for_eval(tcx, param_env);
// try to resolve e.g. associated constants to their definition on an impl, and then
// evaluate the const.
let c = tcx.const_eval_resolve_for_typeck(param_env, unevaluated, span)?;
Ok(c.expect("`ty::Const::eval` called on a non-valtree-compatible type"))
let Some(c) = tcx.const_eval_resolve_for_typeck(param_env, unevaluated, span)?
else {
// This can happen when we run on ill-typed code.
let e = tcx.sess.span_delayed_bug(
span.unwrap_or(DUMMY_SP),
"`ty::Const::eval` called on a non-valtree-compatible type",
);
return Err(e.into());
};
Ok(c)
}
ConstKind::Value(val) => Ok(val),
ConstKind::Error(g) => Err(g.into()),