Auto merge of #2125 - RalfJung:ref-validity, r=RalfJung

test for validity of references pointing to uninhabited types

The new tests for https://github.com/rust-lang/rust/pull/97116
This commit is contained in:
bors 2022-05-18 06:34:48 +00:00
commit c5f1cdb323
3 changed files with 15 additions and 1 deletions

View file

@ -1 +1 @@
e1ec3260d79497080ca86540562d410ba67d2a95
77972d2d0134fb597249b3b64dcf9510a790c34e

View file

@ -0,0 +1,7 @@
#![feature(never_type)]
use std::mem::{transmute, forget};
fn main() { unsafe {
let x: Box<!> = transmute(&mut 42); //~ERROR encountered a box pointing to uninhabited type !
forget(x);
} }

View file

@ -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)
} }