Skip to content

Commit 487e819

Browse files
committed
Fix gce ICE when encountering ill-formed consts
1 parent 4451777 commit 487e819

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

compiler/rustc_infer/src/infer/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1585,11 +1585,13 @@ impl<'tcx> InferCtxt<'tcx> {
15851585
Ok(None) => {
15861586
let tcx = self.tcx;
15871587
let def_id = unevaluated.def;
1588-
span_bug!(
1588+
Err(ErrorHandled::from(tcx.sess.span_delayed_bug(
15891589
tcx.def_span(def_id),
1590-
"unable to construct a constant value for the unevaluated constant {:?}",
1591-
unevaluated
1592-
);
1590+
format!(
1591+
"unable to construct a constant value for the unevaluated constant {:?}",
1592+
unevaluated
1593+
),
1594+
)))
15931595
}
15941596
Err(err) => Err(err),
15951597
}

tests/ui/consts/issue-118545.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
struct Checked<const F: fn()>;
5+
//~^ERROR: using function pointers as const generic parameters is forbidden
6+
7+
fn foo() {}
8+
const _: Checked<foo> = Checked::<foo>;
9+
10+
fn main() {}

tests/ui/consts/issue-118545.stderr

+10
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/issue-118545.rs:4:25
3+
|
4+
LL | struct Checked<const F: fn()>;
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)