about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2021-07-13 00:25:31 +0200
committerRalf Jung <post@ralfj.de>2021-07-14 18:17:49 +0200
commit4ff353cd6e76e8b3b586b8c31b50669675a93e2c (patch)
treed2368d3146e318ccd9d115dbbf049254528a473a
parent4759090d15b176f4a2501c512de776be46f37747 (diff)
downloadrust-4ff353cd6e76e8b3b586b8c31b50669675a93e2c.tar.gz
rust-4ff353cd6e76e8b3b586b8c31b50669675a93e2c.zip
test dynamic check for ptr-int-casts (unleashed)
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.rs9
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.stderr15
2 files changed, 21 insertions, 3 deletions
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.rs b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
index 902d67c1261..22314160c5e 100644
--- a/src/test/ui/consts/miri_unleashed/ptr_arith.rs
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
@@ -11,7 +11,14 @@ static CMP: () = {
     //~| "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
 };
 
-static INT_PTR_ARITH: () = unsafe {
+static PTR_INT_CAST: () = {
+    let x = &0 as *const _ as usize;
+    //~^ ERROR could not evaluate static initializer
+    //~| unable to turn pointer into raw bytes
+    let _v = x == x;
+};
+
+static PTR_INT_TRANSMUTE: () = unsafe {
     let x: usize = std::mem::transmute(&0);
     let _v = x + 0;
     //~^ ERROR could not evaluate static initializer
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.stderr b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
index bd574a53a60..2764d10348a 100644
--- a/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
@@ -5,7 +5,13 @@ 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:16:14
+  --> $DIR/ptr_arith.rs:15:13
+   |
+LL |     let x = &0 as *const _ as usize;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+
+error[E0080]: could not evaluate static initializer
+  --> $DIR/ptr_arith.rs:23:14
    |
 LL |     let _v = x + 0;
    |              ^^^^^ unable to turn pointer into raw bytes
@@ -17,7 +23,12 @@ help: skipping check that does not even have a feature gate
    |
 LL |     let _v = x == x;
    |              ^^^^^^
+help: skipping check that does not even have a feature gate
+  --> $DIR/ptr_arith.rs:15:13
+   |
+LL |     let x = &0 as *const _ as usize;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 2 previous errors; 1 warning emitted
+error: aborting due to 3 previous errors; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0080`.