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