about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-05-16 02:37:26 +0200
committerGitHub <noreply@github.com>2020-05-16 02:37:26 +0200
commit89866ce2c7e860c9c3acf5820c8839d2c4926c0a (patch)
treece58db3c7f8cb1c53ba5d30a73b4241fc5fa2576
parentc1d5640a29d7a61942ff36c05c9b006521983df5 (diff)
parent89543793126b142b8c40b4cc83e284a91cccb499 (diff)
downloadrust-89866ce2c7e860c9c3acf5820c8839d2c4926c0a.tar.gz
rust-89866ce2c7e860c9c3acf5820c8839d2c4926c0a.zip
Rollup merge of #72218 - RalfJung:test-unleashed-ptrs, r=oli-obk
make sure even unleashed miri does not do pointer stuff

r? @oli-obk
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.rs29
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.stderr39
2 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.rs b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
new file mode 100644
index 00000000000..81985f9f625
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
@@ -0,0 +1,29 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(core_intrinsics)]
+#![allow(const_err)]
+
+// A test demonstrating that we prevent doing even trivial
+// pointer arithmetic or comparison during CTFE.
+
+static CMP: () = {
+    let x = &0 as *const _;
+    let _v = x == x;
+    //~^ ERROR could not evaluate static initializer
+    //~| NOTE pointer arithmetic or comparison
+};
+
+static INT_PTR_ARITH: () = unsafe {
+    let x: usize = std::mem::transmute(&0);
+    let _v = x + 0;
+    //~^ ERROR could not evaluate static initializer
+    //~| NOTE pointer-to-integer cast
+};
+
+static PTR_ARITH: () = unsafe {
+    let x = &0 as *const _;
+    let _v = core::intrinsics::offset(x, 0);
+    //~^ ERROR could not evaluate static initializer
+    //~| NOTE calling intrinsic `offset`
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.stderr b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
new file mode 100644
index 00000000000..5bd534a16b8
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
@@ -0,0 +1,39 @@
+error[E0080]: could not evaluate static initializer
+  --> $DIR/ptr_arith.rs:10:14
+   |
+LL |     let _v = x == x;
+   |              ^^^^^^ "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
+
+error[E0080]: could not evaluate static initializer
+  --> $DIR/ptr_arith.rs:17:14
+   |
+LL |     let _v = x + 0;
+   |              ^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
+
+error[E0080]: could not evaluate static initializer
+  --> $DIR/ptr_arith.rs:24:14
+   |
+LL |     let _v = core::intrinsics::offset(x, 0);
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "calling intrinsic `offset`" needs an rfc before being allowed inside constants
+
+warning: skipping const checks
+   |
+help: skipping check for `const_compare_raw_pointers` feature
+  --> $DIR/ptr_arith.rs:10:14
+   |
+LL |     let _v = x == x;
+   |              ^^^^^^
+help: skipping check that does not even have a feature gate
+  --> $DIR/ptr_arith.rs:16:20
+   |
+LL |     let x: usize = std::mem::transmute(&0);
+   |                    ^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+  --> $DIR/ptr_arith.rs:24:14
+   |
+LL |     let _v = core::intrinsics::offset(x, 0);
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.