]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/defaults-in-other-trait-items.rs
feat(rustdoc): open sidebar menu when links inside it are focused
[rust.git] / src / test / ui / associated-types / defaults-in-other-trait-items.rs
1 #![feature(associated_type_defaults)]
2
3 // Associated type defaults may not be assumed inside the trait defining them.
4 // ie. they only resolve to `<Self as Tr>::A`, not the actual type `()`
5 trait Tr {
6     type A = (); //~ NOTE associated type defaults can't be assumed inside the trait defining them
7
8     fn f(p: Self::A) {
9         let () = p;
10         //~^ ERROR mismatched types
11         //~| NOTE expected associated type, found `()`
12         //~| NOTE expected associated type `<Self as Tr>::A`
13     }
14 }
15
16 // An impl that doesn't override the type *can* assume the default.
17 impl Tr for () {
18     fn f(p: Self::A) {
19         let () = p;
20     }
21 }
22
23 impl Tr for u8 {
24     type A = ();
25
26     fn f(p: Self::A) {
27         let () = p;
28     }
29 }
30
31 trait AssocConst {
32     type Ty = u8; //~ NOTE associated type defaults can't be assumed inside the trait defining them
33
34     // Assoc. consts also cannot assume that default types hold
35     const C: Self::Ty = 0u8;
36     //~^ ERROR mismatched types
37     //~| NOTE expected associated type, found `u8`
38     //~| NOTE expected associated type `<Self as AssocConst>::Ty`
39 }
40
41 // An impl can, however
42 impl AssocConst for () {
43     const C: Self::Ty = 0u8;
44 }
45
46 fn main() {}