]> git.lizzy.rs Git - rust.git/commitdiff
test for validity of references pointing to uninhabited types
authorRalf Jung <post@ralfj.de>
Tue, 17 May 2022 15:36:34 +0000 (17:36 +0200)
committerRalf Jung <post@ralfj.de>
Wed, 18 May 2022 06:32:38 +0000 (08:32 +0200)
tests/compile-fail/validity/ref_to_uninhabited1.rs [new file with mode: 0644]
tests/compile-fail/validity/ref_to_uninhabited2.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/validity/ref_to_uninhabited1.rs b/tests/compile-fail/validity/ref_to_uninhabited1.rs
new file mode 100644 (file)
index 0000000..e5522cc
--- /dev/null
@@ -0,0 +1,6 @@
+#![feature(never_type)]
+use std::mem::transmute;
+
+fn main() { unsafe {
+    let _x: &! = transmute(&42); //~ERROR encountered a reference pointing to uninhabited type !
+} }
diff --git a/tests/compile-fail/validity/ref_to_uninhabited2.rs b/tests/compile-fail/validity/ref_to_uninhabited2.rs
new file mode 100644 (file)
index 0000000..3778719
--- /dev/null
@@ -0,0 +1,7 @@
+use std::mem::transmute;
+
+enum Void {}
+
+fn main() { unsafe {
+    let _x: &(i32, Void) = transmute(&42); //~ERROR encountered a reference pointing to uninhabited type (i32, Void)
+} }