Extend test and fix nits

This commit is contained in:
Jonas Schievink 2019-09-19 00:54:47 +02:00
parent 98f02b2362
commit 33d23cdf04
2 changed files with 73 additions and 9 deletions

View file

@ -1,11 +1,11 @@
// compile-fail #![feature(specialization, associated_type_defaults)]
#![feature(specialization)]
// Test that attempting to override a non-default method or one not in the // Test that attempting to override a non-default method or one not in the
// parent impl causes an error // parent impl causes an error.
trait Foo { trait Foo {
type Ty = ();
const CONST: u8 = 123;
fn foo(&self) -> bool { true } fn foo(&self) -> bool { true }
} }
@ -16,6 +16,8 @@ trait Foo {
// Box<i32> Box<i64> Vec<()> Vec<bool> // Box<i32> Box<i64> Vec<()> Vec<bool>
impl<T> Foo for Box<T> { impl<T> Foo for Box<T> {
type Ty = bool;
const CONST: u8 = 0;
fn foo(&self) -> bool { false } fn foo(&self) -> bool { false }
} }
@ -24,18 +26,26 @@ impl Foo for Box<i32> {}
// Can't override a non-`default` fn // Can't override a non-`default` fn
impl Foo for Box<i64> { impl Foo for Box<i64> {
type Ty = Vec<()>;
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
const CONST: u8 = 42;
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
fn foo(&self) -> bool { true } fn foo(&self) -> bool { true }
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default` //~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
} }
// Doesn't mention the method = provided body is used and the method is final // Doesn't mention the item = provided body/value is used and the method is final.
impl<T> Foo for Vec<T> {} impl<T> Foo for Vec<T> {}
// Allowed // Allowed
impl Foo for Vec<()> {} impl Foo for Vec<()> {}
impl Foo for Vec<bool> { impl Foo for Vec<bool> {
type Ty = Vec<()>;
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
const CONST: u8 = 42;
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
fn foo(&self) -> bool { true } fn foo(&self) -> bool { true }
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default` //~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
} }

View file

@ -1,7 +1,39 @@
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default` error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-default-methods-fail.rs:27:5 --> $DIR/specialization-default-methods-fail.rs:29:5
| |
LL | / impl<T> Foo for Box<T> { LL | / impl<T> Foo for Box<T> {
LL | | type Ty = bool;
LL | | const CONST: u8 = 0;
LL | | fn foo(&self) -> bool { false }
LL | | }
| |_- parent `impl` is here
...
LL | type Ty = Vec<()>;
| ^^^^^^^^^^^^^^^^^^ cannot specialize default item `Ty`
|
= note: to specialize, `Ty` in the parent `impl` must be marked `default`
error[E0520]: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-default-methods-fail.rs:31:5
|
LL | / impl<T> Foo for Box<T> {
LL | | type Ty = bool;
LL | | const CONST: u8 = 0;
LL | | fn foo(&self) -> bool { false }
LL | | }
| |_- parent `impl` is here
...
LL | const CONST: u8 = 42;
| ^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `CONST`
|
= note: to specialize, `CONST` in the parent `impl` must be marked `default`
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-default-methods-fail.rs:33:5
|
LL | / impl<T> Foo for Box<T> {
LL | | type Ty = bool;
LL | | const CONST: u8 = 0;
LL | | fn foo(&self) -> bool { false } LL | | fn foo(&self) -> bool { false }
LL | | } LL | | }
| |_- parent `impl` is here | |_- parent `impl` is here
@ -11,8 +43,30 @@ LL | fn foo(&self) -> bool { true }
| |
= note: to specialize, `foo` in the parent `impl` must be marked `default` = note: to specialize, `foo` in the parent `impl` must be marked `default`
error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-default-methods-fail.rs:45:5
|
LL | impl<T> Foo for Vec<T> {}
| ------------------------- parent `impl` is here
...
LL | type Ty = Vec<()>;
| ^^^^^^^^^^^^^^^^^^ cannot specialize default item `Ty`
|
= note: to specialize, `Ty` in the parent `impl` must be marked `default`
error[E0520]: `CONST` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-default-methods-fail.rs:47:5
|
LL | impl<T> Foo for Vec<T> {}
| ------------------------- parent `impl` is here
...
LL | const CONST: u8 = 42;
| ^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `CONST`
|
= note: to specialize, `CONST` in the parent `impl` must be marked `default`
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default` error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-default-methods-fail.rs:39:5 --> $DIR/specialization-default-methods-fail.rs:49:5
| |
LL | impl<T> Foo for Vec<T> {} LL | impl<T> Foo for Vec<T> {}
| ------------------------- parent `impl` is here | ------------------------- parent `impl` is here
@ -22,6 +76,6 @@ LL | fn foo(&self) -> bool { true }
| |
= note: to specialize, `foo` in the parent `impl` must be marked `default` = note: to specialize, `foo` in the parent `impl` must be marked `default`
error: aborting due to 2 previous errors error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0520`. For more information about this error, try `rustc --explain E0520`.