]> git.lizzy.rs Git - rust.git/commitdiff
add test
authorRalf Jung <post@ralfj.de>
Fri, 30 Aug 2019 13:04:12 +0000 (15:04 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 30 Aug 2019 13:04:12 +0000 (15:04 +0200)
src/test/ui/consts/const-eval/dangling.rs [new file with mode: 0644]
src/test/ui/consts/const-eval/dangling.stderr [new file with mode: 0644]

diff --git a/src/test/ui/consts/const-eval/dangling.rs b/src/test/ui/consts/const-eval/dangling.rs
new file mode 100644 (file)
index 0000000..b5d72d4
--- /dev/null
@@ -0,0 +1,13 @@
+#![feature(const_transmute, const_raw_ptr_deref)]
+
+use std::{mem, usize};
+
+// Make sure we error with the right kind of error on a too large slice.
+const TEST: () = { unsafe { //~ NOTE
+    let slice: *const [u8] = mem::transmute((1usize, usize::MAX));
+    let _val = &*slice; //~ ERROR: any use of this value will cause an error
+    //~^ NOTE: total size is bigger than largest supported object
+    //~^^ on by default
+} };
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/dangling.stderr b/src/test/ui/consts/const-eval/dangling.stderr
new file mode 100644 (file)
index 0000000..286de08
--- /dev/null
@@ -0,0 +1,16 @@
+error: any use of this value will cause an error
+  --> $DIR/dangling.rs:8:16
+   |
+LL | / const TEST: () = { unsafe {
+LL | |     let slice: *const [u8] = mem::transmute((1usize, usize::MAX));
+LL | |     let _val = &*slice;
+   | |                ^^^^^^^ invalid slice: total size is bigger than largest supported object
+LL | |
+LL | |
+LL | | } };
+   | |____-
+   |
+   = note: `#[deny(const_err)]` on by default
+
+error: aborting due to previous error
+