Skip to content

Commit

Permalink
Fix gce ICE when encountering ill-formed consts
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwang05 committed Jan 8, 2024
1 parent 11035f9 commit c76394b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
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

0 comments on commit c76394b

Please sign in to comment.