Skip to content

Commit 4eede98

Browse files
committed
Auto merge of #118498 - RalfJung:valtree-ice, r=lcnr
fix an ICE when a valtree failed to evaluate Fixes #118285 r? `@lcnr`
2 parents 0919ad1 + 1d120e6 commit 4eede98

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

compiler/rustc_middle/src/ty/consts.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,16 @@ impl<'tcx> Const<'tcx> {
304304
let (param_env, unevaluated) = unevaluated.prepare_for_eval(tcx, param_env);
305305
// try to resolve e.g. associated constants to their definition on an impl, and then
306306
// evaluate the const.
307-
let c = tcx.const_eval_resolve_for_typeck(param_env, unevaluated, span)?;
308-
Ok(c.expect("`ty::Const::eval` called on a non-valtree-compatible type"))
307+
let Some(c) = tcx.const_eval_resolve_for_typeck(param_env, unevaluated, span)?
308+
else {
309+
// This can happen when we run on ill-typed code.
310+
let e = tcx.sess.span_delayed_bug(
311+
span.unwrap_or(DUMMY_SP),
312+
"`ty::Const::eval` called on a non-valtree-compatible type",
313+
);
314+
return Err(e.into());
315+
};
316+
Ok(c)
309317
}
310318
ConstKind::Value(val) => Ok(val),
311319
ConstKind::Error(g) => Err(g.into()),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
struct Checked<const F: fn(usize) -> bool>;
2+
//~^ ERROR function pointers as const generic parameters is forbidden
3+
fn not_one(val: usize) -> bool { val != 1 }
4+
const _: Checked<not_one> = Checked::<not_one>;
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: using function pointers as const generic parameters is forbidden
2+
--> $DIR/ice-118285-fn-ptr-value.rs:1:25
3+
|
4+
LL | struct Checked<const F: fn(usize) -> bool>;
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the only supported types are integers, `bool` and `char`
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)