@@ -3645,9 +3645,8 @@ fn main() {
36453645"## ,
36463646
36473647E0520 : r##"
3648- A non-default implementation was already made on this type
3649- implementation so it cannot be specialized afterward. Erroneous
3650- code example:
3648+ A non-default implementation was already made on this type so it cannot be
3649+ specialized further. Erroneous code example:
36513650
36523651```compile_fail
36533652#![feature(specialization)]
@@ -3656,14 +3655,18 @@ trait SpaceLama {
36563655 fn fly(&self);
36573656}
36583657
3658+ // applies to all T
36593659impl<T> SpaceLama for T {
36603660 default fn fly(&self) {}
36613661}
36623662
3663+ // non-default impl
3664+ // applies to all `Clone` T and overrides the previous impl
36633665impl<T: Clone> SpaceLama for T {
36643666 fn fly(&self) {}
36653667}
36663668
3669+ // since `i32` is clone, this conflicts with the previous implementation
36673670impl SpaceLama for i32 {
36683671 default fn fly(&self) {}
36693672 // error: item `fly` is provided by an `impl` that specializes
@@ -3672,28 +3675,33 @@ impl SpaceLama for i32 {
36723675}
36733676```
36743677
3675- To fix this error, you need to specialize the implementation on the
3676- parent(s) implementation first. Example:
3678+ Specialization only allows you to override `default` functions in
3679+ implementations.
36773680
3678- ```compile_fail
3681+ To fix this error, you need to mark all the parent implementations as default.
3682+ Example:
3683+
3684+ ```
36793685#![feature(specialization)]
36803686
36813687trait SpaceLama {
36823688 fn fly(&self);
36833689}
36843690
3691+ // applies to all T
36853692impl<T> SpaceLama for T {
36863693 default fn fly(&self) {} // This is a parent implementation.
36873694}
36883695
3696+ // applies to all `Clone` T; overrides the previous impl
36893697impl<T: Clone> SpaceLama for T {
3690- default fn fly(&self) {} // This is a parent implementation but not
3691- // a default one so you need to add default
3692- // keyword.
3698+ default fn fly(&self) {} // This is a parent implementation but was
3699+ // previously not a default one, causing the error
36933700}
36943701
3702+ // applies to i32, overrides the previous two impls
36953703impl SpaceLama for i32 {
3696- default fn fly(&self) {} // And now that's ok!
3704+ fn fly(&self) {} // And now that's ok!
36973705}
36983706```
36993707"## ,
0 commit comments