Skip to content

Commit c76394b

Browse files
committed
Fix gce ICE when encountering ill-formed consts
1 parent 11035f9 commit c76394b

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

compiler/rustc_infer/src/infer/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1580,11 +1580,16 @@ impl<'tcx> InferCtxt<'tcx> {
15801580
Ok(None) => {
15811581
let tcx = self.tcx;
15821582
let def_id = unevaluated.def;
1583-
span_bug!(
1583+
// HACK(generic_const_exprs): We delay the bug instead of immediately ICEing since
1584+
// #117159 may cause us to try to evaluate unevaluatable consts that fail wfcheck
1585+
// despite an error being constructed. See #118545
1586+
Err(ErrorHandled::from(tcx.dcx().span_delayed_bug(
15841587
tcx.def_span(def_id),
1585-
"unable to construct a constant value for the unevaluated constant {:?}",
1586-
unevaluated
1587-
);
1588+
format!(
1589+
"unable to construct a constant value for the unevaluated constant {:?}",
1590+
unevaluated
1591+
),
1592+
)))
15881593
}
15891594
Err(err) => Err(err),
15901595
}

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)