about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Wiedenhöft <richard@wiedenhoeft.xyz>2019-04-30 12:56:38 +0200
committerRichard Wiedenhöft <richard@wiedenhoeft.xyz>2019-05-14 09:41:50 +0200
commitc0b6d3c975915e740548f0ec7bcf5963e7a3b218 (patch)
tree5d742da48713aeefc359d4f27fba5b2bca132f04
parent07e8d844795628ce90415c1dec3536f3e75cc71c (diff)
downloadrust-c0b6d3c975915e740548f0ec7bcf5963e7a3b218.tar.gz
rust-c0b6d3c975915e740548f0ec7bcf5963e7a3b218.zip
Add ui test for const Layout::from_size_align_unchecked
-rw-r--r--src/test/ui/consts/std/alloc.rs10
-rw-r--r--src/test/ui/consts/std/alloc.stderr11
2 files changed, 21 insertions, 0 deletions
diff --git a/src/test/ui/consts/std/alloc.rs b/src/test/ui/consts/std/alloc.rs
new file mode 100644
index 00000000000..65ac7e44926
--- /dev/null
+++ b/src/test/ui/consts/std/alloc.rs
@@ -0,0 +1,10 @@
+use std::alloc::Layout;
+
+// ok
+const LAYOUT_VALID: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x08) };
+
+// not ok, since alignment needs to be non-zero.
+const LAYOUT_INVALID: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
+//~^ ERROR it is undefined behavior to use this value
+
+fn main() {}
diff --git a/src/test/ui/consts/std/alloc.stderr b/src/test/ui/consts/std/alloc.stderr
new file mode 100644
index 00000000000..74a8f3daf6a
--- /dev/null
+++ b/src/test/ui/consts/std/alloc.stderr
@@ -0,0 +1,11 @@
+error[E0080]: it is undefined behavior to use this value
+  --> $DIR/alloc.rs:7:1
+   |
+LL | const LAYOUT_INVALID: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0 at .align_, but expected something greater or equal to 1
+   |
+   = 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`.