Skip to content

Commit d3be26d

Browse files
Improve test
1 parent 1e3c020 commit d3be26d

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/test/ui/associated-types/defaults-specialization.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Tests the interaction of associated type defaults and specialization.
2+
13
// compile-fail
24

35
#![feature(associated_type_defaults, specialization)]
@@ -16,6 +18,13 @@ default impl<T> Tr for A<T> {
1618
//~^ ERROR method `make` has an incompatible type for trait
1719
}
1820

21+
struct A2<T>(T);
22+
// ...same, but in the method body
23+
default impl<T> Tr for A2<T> {
24+
fn make() -> Self::Ty { 0u8 }
25+
//~^ ERROR mismatched types
26+
}
27+
1928
struct B<T>(T);
2029
// Explicitly defaulting the type does the same.
2130
impl<T> Tr for B<T> {
@@ -25,6 +34,15 @@ impl<T> Tr for B<T> {
2534
//~^ ERROR method `make` has an incompatible type for trait
2635
}
2736

37+
struct B2<T>(T);
38+
// ...same, but in the method body
39+
impl<T> Tr for B2<T> {
40+
default type Ty = bool;
41+
42+
fn make() -> Self::Ty { true }
43+
//~^ ERROR mismatched types
44+
}
45+
2846
struct C<T>(T);
2947
// Only the method is defaulted, so this is fine.
3048
impl<T> Tr for C<T> {

src/test/ui/associated-types/defaults-specialization.stderr

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0053]: method `make` has an incompatible type for trait
2-
--> $DIR/defaults-specialization.rs:15:18
2+
--> $DIR/defaults-specialization.rs:17:18
33
|
44
LL | fn make() -> Self::Ty;
55
| -------- type in trait
@@ -11,7 +11,7 @@ LL | fn make() -> u8 { 0 }
1111
found type `fn() -> u8`
1212

1313
error[E0053]: method `make` has an incompatible type for trait
14-
--> $DIR/defaults-specialization.rs:24:18
14+
--> $DIR/defaults-specialization.rs:33:18
1515
|
1616
LL | fn make() -> Self::Ty;
1717
| -------- type in trait
@@ -22,6 +22,29 @@ LL | fn make() -> bool { true }
2222
= note: expected type `fn() -> <B<T> as Tr>::Ty`
2323
found type `fn() -> bool`
2424

25-
error: aborting due to 2 previous errors
25+
error[E0308]: mismatched types
26+
--> $DIR/defaults-specialization.rs:24:29
27+
|
28+
LL | fn make() -> Self::Ty { 0u8 }
29+
| -------- ^^^ expected associated type, found u8
30+
| |
31+
| expected `<A2<T> as Tr>::Ty` because of return type
32+
|
33+
= note: expected type `<A2<T> as Tr>::Ty`
34+
found type `u8`
35+
36+
error[E0308]: mismatched types
37+
--> $DIR/defaults-specialization.rs:42:29
38+
|
39+
LL | fn make() -> Self::Ty { true }
40+
| -------- ^^^^ expected associated type, found bool
41+
| |
42+
| expected `<B2<T> as Tr>::Ty` because of return type
43+
|
44+
= note: expected type `<B2<T> as Tr>::Ty`
45+
found type `bool`
46+
47+
error: aborting due to 4 previous errors
2648

27-
For more information about this error, try `rustc --explain E0053`.
49+
Some errors have detailed explanations: E0053, E0308.
50+
For more information about an error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)