From 30548bb57e3a848568280a72878c3de8b8101d36 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 17 May 2022 17:36:34 +0200 Subject: [PATCH 1/3] 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 0000000000..e5522ccaea --- /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 0000000000..3778719dc5 --- /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) +} } From 092c2b9d9239fce273d1268289da0a1f454a01c2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 18 May 2022 08:32:08 +0200 Subject: [PATCH 2/3] change one of the ref-to-uninhbaited tests to Box --- tests/compile-fail/validity/ref_to_uninhabited1.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/compile-fail/validity/ref_to_uninhabited1.rs b/tests/compile-fail/validity/ref_to_uninhabited1.rs index e5522ccaea..51a3279ffa 100644 --- a/tests/compile-fail/validity/ref_to_uninhabited1.rs +++ b/tests/compile-fail/validity/ref_to_uninhabited1.rs @@ -1,6 +1,7 @@ #![feature(never_type)] -use std::mem::transmute; +use std::mem::{transmute, forget}; fn main() { unsafe { - let _x: &! = transmute(&42); //~ERROR encountered a reference pointing to uninhabited type ! + let x: Box = transmute(&mut 42); //~ERROR encountered a box pointing to uninhabited type ! + forget(x); } } From 439f861101f72b6e6298b87151f23fa3cfcda7f7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 18 May 2022 08:33:10 +0200 Subject: [PATCH 3/3] rustup --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index dd746e9e2a..8788a013ac 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -e1ec3260d79497080ca86540562d410ba67d2a95 +77972d2d0134fb597249b3b64dcf9510a790c34e