Skip to content

Commit a92e21c

Browse files
committed
Rollup merge of rust-lang#56909 - dlrobertson:fix_56762, r=estebank
static eval: Do not ICE on layout size overflow Layout size overflow and typeck eval errors are reported. Trigger a bug only when the eval error is strictly labeled as TooGeneric. Fixes: rust-lang#56762
2 parents 2d6927e + e7e17f9 commit a92e21c

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/librustc_mir/const_eval.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,16 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
692692
let err = error_to_const_error(&ecx, error);
693693
// errors in statics are always emitted as fatal errors
694694
if tcx.is_static(def_id).is_some() {
695-
let err = err.report_as_error(ecx.tcx, "could not evaluate static initializer");
696-
// check that a static never produces `TooGeneric`
695+
let reported_err = err.report_as_error(ecx.tcx,
696+
"could not evaluate static initializer");
697+
// Ensure that if the above error was either `TooGeneric` or `Reported`
698+
// an error must be reported.
697699
if tcx.sess.err_count() == 0 {
698-
span_bug!(ecx.tcx.span, "static eval failure didn't emit an error: {:#?}", err);
700+
tcx.sess.delay_span_bug(err.span,
701+
&format!("static eval failure did not emit an error: {:#?}",
702+
reported_err));
699703
}
700-
err
704+
reported_err
701705
} else if def_id.is_local() {
702706
// constant defined in this crate, we can figure out a lint level!
703707
match tcx.describe_def(def_id) {

src/test/ui/issues/issue-56762.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// only-x86_64
2+
const HUGE_SIZE: usize = !0usize / 8;
3+
4+
5+
pub struct TooBigArray {
6+
arr: [u8; HUGE_SIZE],
7+
}
8+
9+
impl TooBigArray {
10+
pub const fn new() -> Self {
11+
TooBigArray { arr: [0x00; HUGE_SIZE], }
12+
}
13+
}
14+
15+
static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
16+
static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
17+
18+
fn main() { }

src/test/ui/issues/issue-56762.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: the type `[u8; 2305843009213693951]` is too big for the current architecture
2+
3+
error: aborting due to previous error
4+

0 commit comments

Comments
 (0)