mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
fix an ICE when a valtree failed to evaluate
This commit is contained in:
parent
0919ad1838
commit
1d120e6169
@ -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()),
|
||||
|
5
tests/ui/const-generics/ice-118285-fn-ptr-value.rs
Normal file
5
tests/ui/const-generics/ice-118285-fn-ptr-value.rs
Normal file
@ -0,0 +1,5 @@
|
||||
struct Checked<const F: fn(usize) -> bool>;
|
||||
//~^ ERROR function pointers as const generic parameters is forbidden
|
||||
fn not_one(val: usize) -> bool { val != 1 }
|
||||
const _: Checked<not_one> = Checked::<not_one>;
|
||||
fn main() {}
|
10
tests/ui/const-generics/ice-118285-fn-ptr-value.stderr
Normal file
10
tests/ui/const-generics/ice-118285-fn-ptr-value.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
error: using function pointers as const generic parameters is forbidden
|
||||
--> $DIR/ice-118285-fn-ptr-value.rs:1:25
|
||||
|
|
||||
LL | struct Checked<const F: fn(usize) -> bool>;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Reference in New Issue
Block a user