Skip to content

Commit 33d23cd

Browse files
Extend test and fix nits
1 parent 98f02b2 commit 33d23cd

File tree

2 files changed

+72
-8
lines changed

2 files changed

+72
-8
lines changed

src/test/ui/specialization/specialization-default-methods-fail.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// compile-fail
2-
3-
#![feature(specialization)]
1+
#![feature(specialization, associated_type_defaults)]
42

53
// Test that attempting to override a non-default method or one not in the
6-
// parent impl causes an error
4+
// parent impl causes an error.
75

86
trait Foo {
7+
type Ty = ();
8+
const CONST: u8 = 123;
99
fn foo(&self) -> bool { true }
1010
}
1111

@@ -16,6 +16,8 @@ trait Foo {
1616
// Box<i32> Box<i64> Vec<()> Vec<bool>
1717

1818
impl<T> Foo for Box<T> {
19+
type Ty = bool;
20+
const CONST: u8 = 0;
1921
fn foo(&self) -> bool { false }
2022
}
2123

@@ -24,18 +26,26 @@ impl Foo for Box<i32> {}
2426

2527
// Can't override a non-`default` fn
2628
impl Foo for Box<i64> {
29+
type Ty = Vec<()>;
30+
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
31+
const CONST: u8 = 42;
32+
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
2733
fn foo(&self) -> bool { true }
2834
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
2935
}
3036

3137

32-
// Doesn't mention the method = provided body is used and the method is final
38+
// Doesn't mention the item = provided body/value is used and the method is final.
3339
impl<T> Foo for Vec<T> {}
3440

3541
// Allowed
3642
impl Foo for Vec<()> {}
3743

3844
impl Foo for Vec<bool> {
45+
type Ty = Vec<()>;
46+
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
47+
const CONST: u8 = 42;
48+
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
3949
fn foo(&self) -> bool { true }
4050
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
4151
}

src/test/ui/specialization/specialization-default-methods-fail.stderr

+57-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1+
error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
2+
--> $DIR/specialization-default-methods-fail.rs:29:5
3+
|
4+
LL | / impl<T> Foo for Box<T> {
5+
LL | | type Ty = bool;
6+
LL | | const CONST: u8 = 0;
7+
LL | | fn foo(&self) -> bool { false }
8+
LL | | }
9+
| |_- parent `impl` is here
10+
...
11+
LL | type Ty = Vec<()>;
12+
| ^^^^^^^^^^^^^^^^^^ cannot specialize default item `Ty`
13+
|
14+
= note: to specialize, `Ty` in the parent `impl` must be marked `default`
15+
16+
error[E0520]: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
17+
--> $DIR/specialization-default-methods-fail.rs:31:5
18+
|
19+
LL | / impl<T> Foo for Box<T> {
20+
LL | | type Ty = bool;
21+
LL | | const CONST: u8 = 0;
22+
LL | | fn foo(&self) -> bool { false }
23+
LL | | }
24+
| |_- parent `impl` is here
25+
...
26+
LL | const CONST: u8 = 42;
27+
| ^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `CONST`
28+
|
29+
= note: to specialize, `CONST` in the parent `impl` must be marked `default`
30+
131
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
2-
--> $DIR/specialization-default-methods-fail.rs:27:5
32+
--> $DIR/specialization-default-methods-fail.rs:33:5
333
|
434
LL | / impl<T> Foo for Box<T> {
35+
LL | | type Ty = bool;
36+
LL | | const CONST: u8 = 0;
537
LL | | fn foo(&self) -> bool { false }
638
LL | | }
739
| |_- parent `impl` is here
@@ -11,8 +43,30 @@ LL | fn foo(&self) -> bool { true }
1143
|
1244
= note: to specialize, `foo` in the parent `impl` must be marked `default`
1345

46+
error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
47+
--> $DIR/specialization-default-methods-fail.rs:45:5
48+
|
49+
LL | impl<T> Foo for Vec<T> {}
50+
| ------------------------- parent `impl` is here
51+
...
52+
LL | type Ty = Vec<()>;
53+
| ^^^^^^^^^^^^^^^^^^ cannot specialize default item `Ty`
54+
|
55+
= note: to specialize, `Ty` in the parent `impl` must be marked `default`
56+
57+
error[E0520]: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
58+
--> $DIR/specialization-default-methods-fail.rs:47:5
59+
|
60+
LL | impl<T> Foo for Vec<T> {}
61+
| ------------------------- parent `impl` is here
62+
...
63+
LL | const CONST: u8 = 42;
64+
| ^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `CONST`
65+
|
66+
= note: to specialize, `CONST` in the parent `impl` must be marked `default`
67+
1468
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
15-
--> $DIR/specialization-default-methods-fail.rs:39:5
69+
--> $DIR/specialization-default-methods-fail.rs:49:5
1670
|
1771
LL | impl<T> Foo for Vec<T> {}
1872
| ------------------------- parent `impl` is here
@@ -22,6 +76,6 @@ LL | fn foo(&self) -> bool { true }
2276
|
2377
= note: to specialize, `foo` in the parent `impl` must be marked `default`
2478

25-
error: aborting due to 2 previous errors
79+
error: aborting due to 6 previous errors
2680

2781
For more information about this error, try `rustc --explain E0520`.

0 commit comments

Comments
 (0)