diff options
| author | kennytm <kennytm@gmail.com> | 2018-12-23 00:07:34 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-12-23 02:11:47 +0800 |
| commit | a92e21c21542dbc6fe0511b461008471d92b2e85 (patch) | |
| tree | 0ae2d8650ea5442874519ed4af563bb9579c6b16 | |
| parent | 2d6927e9ee8238066bf78b0b42c755ed8aff5d4b (diff) | |
| parent | e7e17f9d1b008a1f06ad8b4ef06c443b4b879bc4 (diff) | |
| download | rust-a92e21c21542dbc6fe0511b461008471d92b2e85.tar.gz rust-a92e21c21542dbc6fe0511b461008471d92b2e85.zip | |
Rollup merge of #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: #56762
| -rw-r--r-- | src/librustc_mir/const_eval.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-56762.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-56762.stderr | 4 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 248c5d2db49..d5bc83aba7b 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -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) { diff --git a/src/test/ui/issues/issue-56762.rs b/src/test/ui/issues/issue-56762.rs new file mode 100644 index 00000000000..97b66b2c7c9 --- /dev/null +++ b/src/test/ui/issues/issue-56762.rs @@ -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() { } diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/issues/issue-56762.stderr new file mode 100644 index 00000000000..83d5dc62e61 --- /dev/null +++ b/src/test/ui/issues/issue-56762.stderr @@ -0,0 +1,4 @@ +error: the type `[u8; 2305843009213693951]` is too big for the current architecture + +error: aborting due to previous error + |
