@@ -3645,55 +3645,63 @@ fn main() {
3645
3645
"## ,
3646
3646
3647
3647
E0520 : 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:
3651
3650
3652
3651
```compile_fail
3653
3652
#![feature(specialization)]
3654
3653
3655
- trait SpaceLama {
3654
+ trait SpaceLlama {
3656
3655
fn fly(&self);
3657
3656
}
3658
3657
3659
- impl<T> SpaceLama for T {
3658
+ // applies to all T
3659
+ impl<T> SpaceLlama for T {
3660
3660
default fn fly(&self) {}
3661
3661
}
3662
3662
3663
- impl<T: Clone> SpaceLama for T {
3663
+ // non-default impl
3664
+ // applies to all `Clone` T and overrides the previous impl
3665
+ impl<T: Clone> SpaceLlama for T {
3664
3666
fn fly(&self) {}
3665
3667
}
3666
3668
3667
- impl SpaceLama for i32 {
3669
+ // since `i32` is clone, this conflicts with the previous implementation
3670
+ impl SpaceLlama for i32 {
3668
3671
default fn fly(&self) {}
3669
3672
// error: item `fly` is provided by an `impl` that specializes
3670
3673
// another, but the item in the parent `impl` is not marked
3671
3674
// `default` and so it cannot be specialized.
3672
3675
}
3673
3676
```
3674
3677
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.
3677
3680
3678
- ```compile_fail
3681
+ To fix this error, you need to mark all the parent implementations as default.
3682
+ Example:
3683
+
3684
+ ```
3679
3685
#![feature(specialization)]
3680
3686
3681
- trait SpaceLama {
3687
+ trait SpaceLlama {
3682
3688
fn fly(&self);
3683
3689
}
3684
3690
3685
- impl<T> SpaceLama for T {
3691
+ // applies to all T
3692
+ impl<T> SpaceLlama for T {
3686
3693
default fn fly(&self) {} // This is a parent implementation.
3687
3694
}
3688
3695
3689
- impl<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.
3696
+ // applies to all `Clone` T; overrides the previous impl
3697
+ impl<T: Clone> SpaceLlama for T {
3698
+ default fn fly(&self) {} // This is a parent implementation but was
3699
+ // previously not a default one, causing the error
3693
3700
}
3694
3701
3695
- impl SpaceLama for i32 {
3696
- default fn fly(&self) {} // And now that's ok!
3702
+ // applies to i32, overrides the previous two impls
3703
+ impl SpaceLlama for i32 {
3704
+ fn fly(&self) {} // And now that's ok!
3697
3705
}
3698
3706
```
3699
3707
"## ,
0 commit comments