1
Fork 0

Review fixes for #32878 (which was accidentally merged)

This commit is contained in:
Manish Goregaokar 2016-04-11 15:23:35 +05:30
parent 49be3dd380
commit 4805e1291a

View file

@ -3645,9 +3645,8 @@ fn main() {
"##, "##,
E0520: r##" E0520: r##"
A non-default implementation was already made on this type A non-default implementation was already made on this type so it cannot be
implementation so it cannot be specialized afterward. Erroneous specialized further. Erroneous code example:
code example:
```compile_fail ```compile_fail
#![feature(specialization)] #![feature(specialization)]
@ -3656,14 +3655,18 @@ trait SpaceLama {
fn fly(&self); fn fly(&self);
} }
// applies to all T
impl<T> SpaceLama for T { impl<T> SpaceLama for T {
default fn fly(&self) {} default fn fly(&self) {}
} }
// non-default impl
// applies to all `Clone` T and overrides the previous impl
impl<T: Clone> SpaceLama for T { impl<T: Clone> SpaceLama for T {
fn fly(&self) {} fn fly(&self) {}
} }
// since `i32` is clone, this conflicts with the previous implementation
impl SpaceLama for i32 { impl SpaceLama for i32 {
default fn fly(&self) {} default fn fly(&self) {}
// error: item `fly` is provided by an `impl` that specializes // error: item `fly` is provided by an `impl` that specializes
@ -3672,28 +3675,33 @@ impl SpaceLama for i32 {
} }
``` ```
To fix this error, you need to specialize the implementation on the Specialization only allows you to override `default` functions in
parent(s) implementation first. Example: implementations.
```compile_fail To fix this error, you need to mark all the parent implementations as default.
Example:
```
#![feature(specialization)] #![feature(specialization)]
trait SpaceLama { trait SpaceLama {
fn fly(&self); fn fly(&self);
} }
// applies to all T
impl<T> SpaceLama for T { impl<T> SpaceLama for T {
default fn fly(&self) {} // This is a parent implementation. default fn fly(&self) {} // This is a parent implementation.
} }
// applies to all `Clone` T; overrides the previous impl
impl<T: Clone> SpaceLama for T { impl<T: Clone> SpaceLama for T {
default fn fly(&self) {} // This is a parent implementation but not default fn fly(&self) {} // This is a parent implementation but was
// a default one so you need to add default // previously not a default one, causing the error
// keyword.
} }
// applies to i32, overrides the previous two impls
impl SpaceLama for i32 { impl SpaceLama for i32 {
default fn fly(&self) {} // And now that's ok! fn fly(&self) {} // And now that's ok!
} }
``` ```
"##, "##,