Merge pull request #4805 from meithecatte/uninhabited-enum-validity
Add a validity testcase for uninhabited variants
This commit is contained in:
commit
aace5bb00b
2 changed files with 30 additions and 0 deletions
17
src/tools/miri/tests/fail/validity/uninhabited_variant.rs
Normal file
17
src/tools/miri/tests/fail/validity/uninhabited_variant.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue