File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed
src/test/ui/associated-types Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ // compile-fail
2+
3+ #![ feature( associated_type_defaults, specialization) ]
4+
5+ trait Tr {
6+ type Ty = u8 ;
7+
8+ fn make ( ) -> Self :: Ty ;
9+ }
10+
11+ struct A < T > ( T ) ;
12+ // In a `default impl`, assoc. types are defaulted as well,
13+ // so their values can't be assumed.
14+ default impl < T > Tr for A < T > {
15+ fn make ( ) -> u8 { 0 }
16+ //~^ ERROR method `make` has an incompatible type for trait
17+ }
18+
19+ struct B < T > ( T ) ;
20+ // Explicitly defaulting the type does the same.
21+ impl < T > Tr for B < T > {
22+ default type Ty = bool ;
23+
24+ fn make ( ) -> bool { true }
25+ //~^ ERROR method `make` has an incompatible type for trait
26+ }
27+
28+ struct C < T > ( T ) ;
29+ // Only the method is defaulted, so this is fine.
30+ impl < T > Tr for C < T > {
31+ type Ty = bool ;
32+
33+ default fn make ( ) -> bool { true }
34+ }
35+
36+ // Defaulted method *can* assume the type, if the default is kept.
37+ struct D < T > ( T ) ;
38+ impl < T > Tr for D < T > {
39+ default fn make ( ) -> u8 { 0 }
40+ }
41+
42+ impl Tr for D < bool > {
43+ fn make ( ) -> u8 { 255 }
44+ }
45+
46+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0053]: method `make` has an incompatible type for trait
2+ --> $DIR/defaults-specialization.rs:15:18
3+ |
4+ LL | fn make() -> Self::Ty;
5+ | -------- type in trait
6+ ...
7+ LL | fn make() -> u8 { 0 }
8+ | ^^ expected associated type, found u8
9+ |
10+ = note: expected type `fn() -> <A<T> as Tr>::Ty`
11+ found type `fn() -> u8`
12+
13+ error[E0053]: method `make` has an incompatible type for trait
14+ --> $DIR/defaults-specialization.rs:24:18
15+ |
16+ LL | fn make() -> Self::Ty;
17+ | -------- type in trait
18+ ...
19+ LL | fn make() -> bool { true }
20+ | ^^^^ expected associated type, found bool
21+ |
22+ = note: expected type `fn() -> <B<T> as Tr>::Ty`
23+ found type `fn() -> bool`
24+
25+ error: aborting due to 2 previous errors
26+
27+ For more information about this error, try `rustc --explain E0053`.
You can’t perform that action at this time.
0 commit comments