File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #![ feature( never_type) ]
2+
3+ #[ repr( C ) ]
4+ #[ allow( dead_code) ]
5+ enum E {
6+ V1 , // discriminant: 0
7+ V2 ( !) , // 1
8+ }
9+
10+ fn main ( ) {
11+ assert_eq ! ( std:: mem:: size_of:: <E >( ) , 4 ) ;
12+
13+ let val = 1u32 ;
14+ let ptr = ( & raw const val) . cast :: < E > ( ) ;
15+ unsafe { ptr. read ( ) } ; //~ ERROR: encountered an uninhabited enum variant
16+ }
Original file line number Diff line number Diff line change 1+ error: Undefined Behavior: constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
2+ --> tests/fail/validity/uninhabited_variant.rs:LL:CC
3+ |
4+ LL | unsafe { ptr.read() };
5+ | ^^^^^^^^^^ Undefined Behavior occurred here
6+ |
7+ = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+ = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
10+ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
11+
12+ error: aborting due to 1 previous error
13+
You can’t perform that action at this time.
0 commit comments