]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/defaults-cyclic-fail-1.rs
Rollup merge of #75837 - GuillaumeGomez:fix-font-color-help-button, r=Cldfire
[rust.git] / src / test / ui / associated-types / defaults-cyclic-fail-1.rs
1 #![feature(associated_type_defaults)]
2
3 // Having a cycle in assoc. type defaults is okay...
4 trait Tr {
5     type A = Self::B;
6     type B = Self::A;
7 }
8
9 // ...but is an error in any impl that doesn't override at least one of the defaults
10 impl Tr for () {}
11 //~^ ERROR overflow evaluating the requirement
12
13 // As soon as at least one is redefined, it works:
14 impl Tr for u8 {
15     type A = u8;
16 }
17
18 impl Tr for u16 {
19     type B = ();
20 }
21
22 impl Tr for u32 {
23     type A = ();
24     type B = u8;
25 }
26
27 // ...but only if this actually breaks the cycle
28 impl Tr for bool {
29     //~^ ERROR type mismatch resolving `<bool as Tr>::B == _`
30     type A = Box<Self::B>;
31     //~^ ERROR type mismatch resolving `<bool as Tr>::B == _`
32 }
33 // (the error is shown twice for some reason)
34
35 impl Tr for usize {
36     //~^ ERROR type mismatch resolving `<usize as Tr>::B == _`
37     type B = &'static Self::A;
38     //~^ ERROR type mismatch resolving `<usize as Tr>::A == _`
39 }
40
41 fn main() {
42     // We don't check that the types project correctly because the cycle errors stop compilation
43     // before `main` is type-checked.
44     // `defaults-cyclic-pass-1.rs` does this.
45 }