@@ -3644,6 +3644,60 @@ fn main() {
3644
3644
```
3645
3645
"## ,
3646
3646
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:
3651
+
3652
+ ```compile_fail
3653
+ #![feature(specialization)]
3654
+
3655
+ trait SpaceLama {
3656
+ fn fly(&self);
3657
+ }
3658
+
3659
+ impl<T> SpaceLama for T {
3660
+ default fn fly(&self) {}
3661
+ }
3662
+
3663
+ impl<T: Clone> SpaceLama for T {
3664
+ fn fly(&self) {}
3665
+ }
3666
+
3667
+ impl SpaceLama for i32 {
3668
+ default fn fly(&self) {}
3669
+ // error: item `fly` is provided by an `impl` that specializes
3670
+ // another, but the item in the parent `impl` is not marked
3671
+ // `default` and so it cannot be specialized.
3672
+ }
3673
+ ```
3674
+
3675
+ To fix this error, you need to specialize the implementation on the
3676
+ parent(s) implementation first. Example:
3677
+
3678
+ ```compile_fail
3679
+ #![feature(specialization)]
3680
+
3681
+ trait SpaceLama {
3682
+ fn fly(&self);
3683
+ }
3684
+
3685
+ impl<T> SpaceLama for T {
3686
+ default fn fly(&self) {} // This is a parent implementation.
3687
+ }
3688
+
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.
3693
+ }
3694
+
3695
+ impl SpaceLama for i32 {
3696
+ default fn fly(&self) {} // And now that's ok!
3697
+ }
3698
+ ```
3699
+ "## ,
3700
+
3647
3701
}
3648
3702
3649
3703
register_diagnostics ! {
@@ -3720,6 +3774,5 @@ register_diagnostics! {
3720
3774
// type `{}` was overridden
3721
3775
E0436 , // functional record update requires a struct
3722
3776
E0513 , // no type for local variable ..
3723
- E0520 , // cannot specialize non-default item
3724
3777
E0521 // redundant default implementations of trait
3725
3778
}
0 commit comments