From 30548bb57e3a848568280a72878c3de8b8101d36 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 17 May 2022 17:36:34 +0200 Subject: [PATCH] test for validity of references pointing to uninhabited types --- tests/compile-fail/validity/ref_to_uninhabited1.rs | 6 ++++++ tests/compile-fail/validity/ref_to_uninhabited2.rs | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/compile-fail/validity/ref_to_uninhabited1.rs create mode 100644 tests/compile-fail/validity/ref_to_uninhabited2.rs diff --git a/tests/compile-fail/validity/ref_to_uninhabited1.rs b/tests/compile-fail/validity/ref_to_uninhabited1.rs new file mode 100644 index 00000000000..e5522ccaeab --- /dev/null +++ b/tests/compile-fail/validity/ref_to_uninhabited1.rs @@ -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 index 00000000000..3778719dc58 --- /dev/null +++ b/tests/compile-fail/validity/ref_to_uninhabited2.rs @@ -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) +} }