2021-03-31 08:09:16 +00:00
|
|
|
// stderr-per-bitwidth
|
2018-11-01 14:14:51 +01:00
|
|
|
|
2019-08-30 09:35:02 +02:00
|
|
|
#[repr(C)]
|
2018-06-04 18:32:06 +02:00
|
|
|
union DummyUnion {
|
2020-07-05 13:48:06 +02:00
|
|
|
unit: (),
|
2018-06-04 18:32:06 +02:00
|
|
|
u8: u8,
|
|
|
|
bool: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum Enum {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
2019-08-30 09:35:02 +02:00
|
|
|
#[repr(C)]
|
2018-06-04 18:32:06 +02:00
|
|
|
union Foo {
|
|
|
|
a: bool,
|
|
|
|
b: Enum,
|
|
|
|
}
|
|
|
|
|
2019-08-30 09:35:02 +02:00
|
|
|
#[repr(C)]
|
2018-06-04 18:32:06 +02:00
|
|
|
union Bar {
|
|
|
|
foo: Foo,
|
|
|
|
u8: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
// the value is not valid for bools
|
|
|
|
const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool};
|
2018-08-26 15:19:34 +02:00
|
|
|
//~^ ERROR it is undefined behavior to use this value
|
2020-07-05 13:48:06 +02:00
|
|
|
const UNINIT_BOOL: bool = unsafe { DummyUnion { unit: () }.bool};
|
2022-08-01 19:05:20 -04:00
|
|
|
//~^ ERROR evaluation of constant value failed
|
|
|
|
//~| uninitialized
|
2018-06-04 18:32:06 +02:00
|
|
|
|
|
|
|
// The value is not valid for any union variant, but that's fine
|
|
|
|
// unions are just a convenient way to transmute bits around
|
|
|
|
const BAD_UNION: Foo = unsafe { Bar { u8: 42 }.foo };
|
|
|
|
|
|
|
|
|
2018-10-02 18:07:40 +02:00
|
|
|
fn main() {}
|