Skip to content
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

static eval: Do not ICE on layout size overflow #56909

Merged
merged 1 commit into from
Dec 23, 2018
Merged
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
12 changes: 8 additions & 4 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,16 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
let err = error_to_const_error(&ecx, error);
// errors in statics are always emitted as fatal errors
if tcx.is_static(def_id).is_some() {
let err = err.report_as_error(ecx.tcx, "could not evaluate static initializer");
// check that a static never produces `TooGeneric`
let reported_err = err.report_as_error(ecx.tcx,
"could not evaluate static initializer");
// Ensure that if the above error was either `TooGeneric` or `Reported`
// an error must be reported.
if tcx.sess.err_count() == 0 {
span_bug!(ecx.tcx.span, "static eval failure didn't emit an error: {:#?}", err);
tcx.sess.delay_span_bug(err.span,
&format!("static eval failure did not emit an error: {:#?}",
reported_err));
}
err
reported_err
} else if def_id.is_local() {
// constant defined in this crate, we can figure out a lint level!
match tcx.describe_def(def_id) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/issues/issue-56762.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// only-x86_64
const HUGE_SIZE: usize = !0usize / 8;


pub struct TooBigArray {
arr: [u8; HUGE_SIZE],
}

impl TooBigArray {
pub const fn new() -> Self {
TooBigArray { arr: [0x00; HUGE_SIZE], }
}
}

static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];

fn main() { }
4 changes: 4 additions & 0 deletions src/test/ui/issues/issue-56762.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: the type `[u8; 2305843009213693951]` is too big for the current architecture

error: aborting due to previous error