about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-08-30 15:04:12 +0200
committerRalf Jung <post@ralfj.de>2019-08-30 15:04:12 +0200
commitbb3474994b94472a292fec6ebfdc21cda4d8cc70 (patch)
tree3462acaf611d27ca5349b02334ff74a49794154b /src
parent38f6b96aae299b82d333d72828f3ea589849d907 (diff)
downloadrust-bb3474994b94472a292fec6ebfdc21cda4d8cc70.tar.gz
rust-bb3474994b94472a292fec6ebfdc21cda4d8cc70.zip
add test
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/consts/const-eval/dangling.rs13
-rw-r--r--src/test/ui/consts/const-eval/dangling.stderr16
2 files changed, 29 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-eval/dangling.rs b/src/test/ui/consts/const-eval/dangling.rs
new file mode 100644
index 00000000000..b5d72d46f28
--- /dev/null
+++ b/src/test/ui/consts/const-eval/dangling.rs
@@ -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
index 00000000000..286de080097
--- /dev/null
+++ b/src/test/ui/consts/const-eval/dangling.stderr
@@ -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
+