Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9aaef06
commit a0cf531
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/test/ui/specialization/specialization-default-methods-fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// compile-fail | ||
|
||
#![feature(specialization)] | ||
|
||
// Test that attempting to override a non-default method or one not in the | ||
// parent impl causes an error | ||
|
||
trait Foo { | ||
fn foo(&self) -> bool { true } | ||
} | ||
|
||
// Specialization tree for Foo: | ||
// | ||
// Box<T> Vec<T> | ||
// / \ / \ | ||
// Box<i32> Box<i64> Vec<()> Vec<bool> | ||
|
||
impl<T> Foo for Box<T> { | ||
fn foo(&self) -> bool { false } | ||
} | ||
|
||
// Allowed | ||
impl Foo for Box<i32> {} | ||
|
||
// Can't override a non-`default` fn | ||
impl Foo for Box<i64> { | ||
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 | ||
impl<T> Foo for Vec<T> {} | ||
|
||
// Allowed | ||
impl Foo for Vec<()> {} | ||
|
||
impl Foo for Vec<bool> { | ||
fn foo(&self) -> bool { true } | ||
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default` | ||
} | ||
|
||
fn main() {} |
27 changes: 27 additions & 0 deletions
27
src/test/ui/specialization/specialization-default-methods-fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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 | ||
| | ||
LL | / impl<T> Foo for Box<T> { | ||
LL | | fn foo(&self) -> bool { false } | ||
LL | | } | ||
| |_- parent `impl` is here | ||
... | ||
LL | fn foo(&self) -> bool { true } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo` | ||
| | ||
= note: to specialize, `foo` 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 | ||
| | ||
LL | impl<T> Foo for Vec<T> {} | ||
| ------------------------- parent `impl` is here | ||
... | ||
LL | fn foo(&self) -> bool { true } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo` | ||
| | ||
= note: to specialize, `foo` in the parent `impl` must be marked `default` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0520`. |