Skip to content

Fix gce ICE when encountering ill-formed consts #119060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,11 +1580,16 @@ impl<'tcx> InferCtxt<'tcx> {
Ok(None) => {
let tcx = self.tcx;
let def_id = unevaluated.def;
span_bug!(
// HACK(generic_const_exprs): We delay the bug instead of immediately ICEing since
// #117159 may cause us to try to evaluate unevaluatable consts that fail wfcheck
// despite an error being constructed. See #118545
Err(ErrorHandled::from(tcx.dcx().span_delayed_bug(
tcx.def_span(def_id),
"unable to construct a constant value for the unevaluated constant {:?}",
unevaluated
);
format!(
"unable to construct a constant value for the unevaluated constant {:?}",
unevaluated
),
)))
}
Err(err) => Err(err),
}
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/consts/issue-118545.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

struct Checked<const F: fn()>;
//~^ERROR: using function pointers as const generic parameters is forbidden

fn foo() {}
const _: Checked<foo> = Checked::<foo>;

fn main() {}
10 changes: 10 additions & 0 deletions tests/ui/consts/issue-118545.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-118545.rs:4:25
|
LL | struct Checked<const F: fn()>;
| ^^^^
|
= note: the only supported types are integers, `bool` and `char`

error: aborting due to 1 previous error