summaryrefslogtreecommitdiffstats
path: root/src/test/ui/associated-consts/defaults-cyclic-pass.rs
blob: 82105f25f92407df8a732dc0bd8a1f41aae926bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// run-pass

// Cyclic assoc. const defaults don't error unless *used*
trait Tr {
    const A: u8 = Self::B;
    const B: u8 = Self::A;
}

// This impl is *allowed* unless its assoc. consts are used, matching the
// behavior without defaults.
impl Tr for () {}

// Overriding either constant breaks the cycle
impl Tr for u8 {
    const A: u8 = 42;
}

impl Tr for u16 {
    const B: u8 = 0;
}

impl Tr for u32 {
    const A: u8 = 100;
    const B: u8 = 123;
}

fn main() {
    assert_eq!(<u8 as Tr>::A, 42);
    assert_eq!(<u8 as Tr>::B, 42);

    assert_eq!(<u16 as Tr>::A, 0);
    assert_eq!(<u16 as Tr>::B, 0);

    assert_eq!(<u32 as Tr>::A, 100);
    assert_eq!(<u32 as Tr>::B, 123);
}