]> git.lizzy.rs Git - rust.git/blob - src/test/ui/enum/enum-discrim-too-small.rs
Rollup merge of #102092 - kxxt:patch-1, r=joshtriplett
[rust.git] / src / test / ui / enum / enum-discrim-too-small.rs
1 #[repr(u8)]
2 enum Eu8 {
3     Au8 = 23,
4     Bu8 = 223,
5     Cu8 = -23,
6     //~^ ERROR cannot apply unary operator `-` to type `u8`
7 }
8
9 #[repr(u16)]
10 enum Eu16 {
11     Au16 = 23,
12     Bu16 = 55555,
13     Cu16 = -22333,
14     //~^ ERROR cannot apply unary operator `-` to type `u16`
15 }
16
17 #[repr(u32)]
18 enum Eu32 {
19     Au32 = 23,
20     Bu32 = 3_000_000_000,
21     Cu32 = -2_000_000_000,
22     //~^ ERROR cannot apply unary operator `-` to type `u32`
23 }
24
25 #[repr(u64)]
26 enum Eu64 {
27     Au32 = 23,
28     Bu32 = 3_000_000_000,
29     Cu32 = -2_000_000_000,
30     //~^ ERROR cannot apply unary operator `-` to type `u64`
31 }
32
33 // u64 currently allows negative numbers, and i64 allows numbers greater than `1<<63`.  This is a
34 // little counterintuitive, but since the discriminant can store all the bits, and extracting it
35 // with a cast requires specifying the signedness, there is no loss of information in those cases.
36 // This also applies to isize and usize on 64-bit targets.
37
38 pub fn main() { }