]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/defaults-in-other-trait-items.rs
Fix rebase damage
[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 = ();
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         //~| NOTE consider constraining the associated type
14         //~| NOTE for more information, visit
15     }
16 }
17
18 // An impl that doesn't override the type *can* assume the default.
19 impl Tr for () {
20     fn f(p: Self::A) {
21         let () = p;
22     }
23 }
24
25 impl Tr for u8 {
26     type A = ();
27
28     fn f(p: Self::A) {
29         let () = p;
30     }
31 }
32
33 trait AssocConst {
34     type Ty = u8;
35
36     // Assoc. consts also cannot assume that default types hold
37     const C: Self::Ty = 0u8;
38     //~^ ERROR mismatched types
39     //~| NOTE expected associated type, found `u8`
40     //~| NOTE expected associated type `<Self as AssocConst>::Ty`
41     //~| NOTE consider constraining the associated type
42     //~| NOTE for more information, visit
43 }
44
45 // An impl can, however
46 impl AssocConst for () {
47     const C: Self::Ty = 0u8;
48 }
49
50 fn main() {}