about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-25 23:21:06 +0200
committerGitHub <noreply@github.com>2019-07-25 23:21:06 +0200
commit6e8d7b6e48da6078b4196c0ca47d41b7a1224fa1 (patch)
treec9c0e42dfac594a8608fefbb8cfc5fbfebcfe8bb
parentfe07132c80be874f47ddebe1456d0c3af2d8e36b (diff)
parentf49a96501d4f11cb08c382bd8180a5a5db59213d (diff)
Rollup merge of #62930 - iluuu1994:test-for-51559, r=oli-obk
Add test for #51559

Closes #51559
-rw-r--r--src/test/ui/consts/issue-51559.rs7
-rw-r--r--src/test/ui/consts/issue-51559.stderr11
2 files changed, 18 insertions, 0 deletions
diff --git a/src/test/ui/consts/issue-51559.rs b/src/test/ui/consts/issue-51559.rs
new file mode 100644
index 00000000000..42994726938
--- /dev/null
+++ b/src/test/ui/consts/issue-51559.rs
@@ -0,0 +1,7 @@
+#![feature(const_raw_ptr_to_usize_cast)]
+
+const BAR: *mut () = ((|| 3) as fn() -> i32) as *mut ();
+pub const FOO: usize = unsafe { BAR as usize };
+//~^ ERROR it is undefined behavior to use this value
+
+fn main() {}
diff --git a/src/test/ui/consts/issue-51559.stderr b/src/test/ui/consts/issue-51559.stderr
new file mode 100644
index 00000000000..917c54ddaef
--- /dev/null
+++ b/src/test/ui/consts/issue-51559.stderr
@@ -0,0 +1,11 @@
+error[E0080]: it is undefined behavior to use this value
+  --> $DIR/issue-51559.rs:4:1
+   |
+LL | pub const FOO: usize = unsafe { BAR as usize };
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain (non-pointer) bytes
+   |
+   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.