diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index fa694f09f178d..b5174c1a35d40 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -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), } diff --git a/tests/ui/consts/issue-118545.rs b/tests/ui/consts/issue-118545.rs new file mode 100644 index 0000000000000..16c605a2b3806 --- /dev/null +++ b/tests/ui/consts/issue-118545.rs @@ -0,0 +1,10 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +struct Checked; +//~^ERROR: using function pointers as const generic parameters is forbidden + +fn foo() {} +const _: Checked = Checked::; + +fn main() {} diff --git a/tests/ui/consts/issue-118545.stderr b/tests/ui/consts/issue-118545.stderr new file mode 100644 index 0000000000000..c5144ef833c05 --- /dev/null +++ b/tests/ui/consts/issue-118545.stderr @@ -0,0 +1,10 @@ +error: using function pointers as const generic parameters is forbidden + --> $DIR/issue-118545.rs:4:25 + | +LL | struct Checked; + | ^^^^ + | + = note: the only supported types are integers, `bool` and `char` + +error: aborting due to 1 previous error +