about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWesley Wiser <wwiser@gmail.com>2018-06-30 15:25:07 -0400
committerWesley Wiser <wwiser@gmail.com>2018-07-01 10:31:15 -0400
commit46512e09c9f97a68a36e2d72e3be766b1e76a1a0 (patch)
tree7393478284b780269121f7ef84717eb4f4bd4984
parentfaef6a30e6a470fd46444642c62f4a1ff378ca7f (diff)
downloadrust-46512e09c9f97a68a36e2d72e3be766b1e76a1a0.tar.gz
rust-46512e09c9f97a68a36e2d72e3be766b1e76a1a0.zip
Add two regression tests for const eval
-rw-r--r--src/test/compile-fail/const-err4.rs24
-rw-r--r--src/test/run-pass/const-repeated-values.rs19
2 files changed, 43 insertions, 0 deletions
diff --git a/src/test/compile-fail/const-err4.rs b/src/test/compile-fail/const-err4.rs
new file mode 100644
index 00000000000..09ebf1681c5
--- /dev/null
+++ b/src/test/compile-fail/const-err4.rs
@@ -0,0 +1,24 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[derive(Copy, Clone)]
+union Foo {
+    a: isize,
+    b: (),
+}
+
+enum Bar {
+    Boo = [unsafe { Foo { b: () }.a }; 4][3],
+    //~^ ERROR constant evaluation of enum discriminant resulted in non-integer
+}
+
+fn main() {
+    assert_ne!(Bar::Boo as isize, 0);
+}
diff --git a/src/test/run-pass/const-repeated-values.rs b/src/test/run-pass/const-repeated-values.rs
new file mode 100644
index 00000000000..1d749a2626e
--- /dev/null
+++ b/src/test/run-pass/const-repeated-values.rs
@@ -0,0 +1,19 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+const FOO: isize = 42;
+
+enum Bar {
+    Boo = *[&FOO; 4][3],
+}
+
+fn main() {
+    assert_eq!(Bar::Boo as isize, 42);
+}