]> git.proxmox.com Git - rustc.git/blob - src/test/ui/associated-consts/defaults-not-assumed-pass.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / associated-consts / defaults-not-assumed-pass.rs
1 // run-pass
2
3 trait Tr {
4 const A: u8 = 255;
5
6 // This should not be a constant evaluation error (overflow). The value of
7 // `Self::A` must not be assumed to hold inside the trait.
8 const B: u8 = Self::A + 1;
9 }
10
11 // An impl that doesn't override any constant will NOT cause a const eval error
12 // just because it's defined, but only if the bad constant is used anywhere.
13 // This matches the behavior without defaults.
14 impl Tr for () {}
15
16 // An impl that overrides either constant with a suitable value will be fine.
17 impl Tr for u8 {
18 const A: u8 = 254;
19 }
20
21 impl Tr for u16 {
22 const B: u8 = 0;
23 }
24
25 impl Tr for u32 {
26 const A: u8 = 254;
27 const B: u8 = 0;
28 }
29
30 fn main() {
31 assert_eq!(<() as Tr>::A, 255);
32 //assert_eq!(<() as Tr>::B, 0); // using this is an error
33
34 assert_eq!(<u8 as Tr>::A, 254);
35 assert_eq!(<u8 as Tr>::B, 255);
36
37 assert_eq!(<u16 as Tr>::A, 255);
38 assert_eq!(<u16 as Tr>::B, 0);
39
40 assert_eq!(<u32 as Tr>::A, 254);
41 assert_eq!(<u32 as Tr>::B, 0);
42 }