about summary refs log tree commit diff
path: root/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs')
-rw-r--r--src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
new file mode 100644
index 00000000000..59757908acd
--- /dev/null
+++ b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
@@ -0,0 +1,24 @@
+#![feature(const_fn)]
+#![feature(const_transmute)]
+
+const fn foo() -> ! {
+    unsafe { std::mem::transmute(()) }
+    //~^ ERROR evaluation of constant value failed
+    //~| WARN the type `!` does not permit zero-initialization [invalid_value]
+}
+
+#[derive(Clone, Copy)]
+enum Empty { }
+
+#[warn(const_err)]
+const FOO: [Empty; 3] = [foo(); 3];
+//~^ WARN any use of this value will cause an error
+#[warn(const_err)]
+const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
+//~^ ERROR it is undefined behavior to use this value
+//~| WARN the type `Empty` does not permit zero-initialization
+
+fn main() {
+    FOO;
+    BAR;
+}