Closed
Description
This code fails with a compile error when using the smaller unsigned types (u8, u16, u32) as a representation for the enum. For signed types or u64 the same code compiles fine so it seems there is some issue with truncation for unsigned types.
As a workaround it is possible to use an explicit cast (!0 as u8).
#[repr(u8)]
enum Test {
A = 0,
B = !0
}
fn main() {
}
error.rs:6:5: 6:11 error: discriminant value outside specified type [E0082]
error.rs:6 B = !0
^~~~~~
error.rs:3:8: 3:11 note: discriminant type specified here
error.rs:3 #[repr(u8)]