]> git.lizzy.rs Git - rust.git/blob - tests/ui/associated-types/defaults-in-other-trait-items.rs
Link to the LLVM issue from a comment on `SpecOptionPartialEq`
[rust.git] / tests / 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         //~| NOTE this expression has type `<Self as Tr>::A`
14     }
15 }
16
17 // An impl that doesn't override the type *can* assume the default.
18 impl Tr for () {
19     fn f(p: Self::A) {
20         let () = p;
21     }
22 }
23
24 impl Tr for u8 {
25     type A = ();
26
27     fn f(p: Self::A) {
28         let () = p;
29     }
30 }
31
32 trait AssocConst {
33     type Ty = u8; //~ NOTE associated type defaults can't be assumed inside the trait defining them
34
35     // Assoc. consts also cannot assume that default types hold
36     const C: Self::Ty = 0u8;
37     //~^ ERROR mismatched types
38     //~| NOTE expected associated type, found `u8`
39     //~| NOTE expected associated type `<Self as AssocConst>::Ty`
40 }
41
42 // An impl can, however
43 impl AssocConst for () {
44     const C: Self::Ty = 0u8;
45 }
46
47 fn main() {}