Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/fail/validity/uninhabited_variant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// NOTE: this is essentially a smoke-test, with more comprehensive tests living in the rustc
// repository at tests/ui/consts/const-eval/ub-enum.rs
#![feature(never_type)]

#[repr(C)]
#[allow(dead_code)]
enum E {
V1, // discriminant: 0
V2(!), // 1
}

fn main() {
unsafe {
std::mem::transmute::<u32, E>(1);
//~^ ERROR: encountered an uninhabited enum variant
}
}
13 changes: 13 additions & 0 deletions tests/fail/validity/uninhabited_variant.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: Undefined Behavior: constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
--> tests/fail/validity/uninhabited_variant.rs:LL:CC
|
LL | std::mem::transmute::<u32, E>(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error