Skip to content

Commit

Permalink
Extend test and fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Oct 5, 2019
1 parent 98f02b2 commit 33d23cd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/test/ui/specialization/specialization-default-methods-fail.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// compile-fail

#![feature(specialization)]
#![feature(specialization, associated_type_defaults)]

// 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 {
type Ty = ();
const CONST: u8 = 123;
fn foo(&self) -> bool { true }
}

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

impl<T> Foo for Box<T> {
type Ty = bool;
const CONST: u8 = 0;
fn foo(&self) -> bool { false }
}

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

// Can't override a non-`default` fn
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 }
//~^ 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> {}

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

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 }
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-default-methods-fail.rs:29: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 | 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:27:5
--> $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 | | }
| |_- parent `impl` is here
Expand All @@ -11,8 +43,30 @@ LL | fn foo(&self) -> bool { true }
|
= 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`
--> $DIR/specialization-default-methods-fail.rs:39:5
--> $DIR/specialization-default-methods-fail.rs:49:5
|
LL | impl<T> Foo for Vec<T> {}
| ------------------------- parent `impl` is here
Expand All @@ -22,6 +76,6 @@ LL | fn foo(&self) -> bool { true }
|
= 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`.

0 comments on commit 33d23cd

Please sign in to comment.