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 
f(p: Self::A)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 () {
f(p: Self::A)18     fn f(p: Self::A) {
19         let () = p;
20     }
21 }
22 
23 impl Tr for u8 {
24     type A = ();
25 
f(p: Self::A)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 
main()46 fn main() {}
47