Skip to content

Commit

Permalink
Auto merge of #2125 - RalfJung:ref-validity, r=RalfJung
Browse files Browse the repository at this point in the history
test for validity of references pointing to uninhabited types

The new tests for rust-lang/rust#97116
  • Loading branch information
bors committed May 18, 2022
2 parents a5cf247 + 439f861 commit c5f1cdb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e1ec3260d79497080ca86540562d410ba67d2a95
77972d2d0134fb597249b3b64dcf9510a790c34e
7 changes: 7 additions & 0 deletions tests/compile-fail/validity/ref_to_uninhabited1.rs
Original file line number Diff line number Diff line change
@@ -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);
} }
7 changes: 7 additions & 0 deletions tests/compile-fail/validity/ref_to_uninhabited2.rs
Original file line number Diff line number Diff line change
@@ -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)
} }

0 comments on commit c5f1cdb

Please sign in to comment.