Skip to content

Review fixes for #32878 #32880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3645,55 +3645,63 @@ fn main() {
"##,

E0520: r##"
A non-default implementation was already made on this type
implementation so it cannot be specialized afterward. Erroneous
code example:
A non-default implementation was already made on this type so it cannot be
specialized further. Erroneous code example:

```compile_fail
#![feature(specialization)]

trait SpaceLama {
trait SpaceLlama {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why SpaceLlama?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Llama is the animal, Lama is the Buddhist monk 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how rust improves every day 🌞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bluss: Well, I invite you to take a look at my previous error explanations/test cases PRs then. :p

fn fly(&self);
}

impl<T> SpaceLama for T {
// applies to all T
impl<T> SpaceLlama for T {
default fn fly(&self) {}
}

impl<T: Clone> SpaceLama for T {
// non-default impl
// applies to all `Clone` T and overrides the previous impl
impl<T: Clone> SpaceLlama for T {
fn fly(&self) {}
}

impl SpaceLama for i32 {
// since `i32` is clone, this conflicts with the previous implementation
impl SpaceLlama for i32 {
default fn fly(&self) {}
// error: item `fly` is provided by an `impl` that specializes
// another, but the item in the parent `impl` is not marked
// `default` and so it cannot be specialized.
}
```

To fix this error, you need to specialize the implementation on the
parent(s) implementation first. Example:
Specialization only allows you to override `default` functions in
implementations.

```compile_fail
To fix this error, you need to mark all the parent implementations as default.
Example:

```
#![feature(specialization)]

trait SpaceLama {
trait SpaceLlama {
fn fly(&self);
}

impl<T> SpaceLama for T {
// applies to all T
impl<T> SpaceLlama for T {
default fn fly(&self) {} // This is a parent implementation.
}

impl<T: Clone> SpaceLama for T {
default fn fly(&self) {} // This is a parent implementation but not
// a default one so you need to add default
// keyword.
// applies to all `Clone` T; overrides the previous impl
impl<T: Clone> SpaceLlama for T {
default fn fly(&self) {} // This is a parent implementation but was
// previously not a default one, causing the error
}

impl SpaceLama for i32 {
default fn fly(&self) {} // And now that's ok!
// applies to i32, overrides the previous two impls
impl SpaceLlama for i32 {
fn fly(&self) {} // And now that's ok!
}
```
"##,
Expand Down