Skip to content

Commit 4805e12

Browse files
committed
Review fixes for #32878 (which was accidentally merged)
1 parent 49be3dd commit 4805e12

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/librustc_typeck/diagnostics.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -3645,9 +3645,8 @@ fn main() {
36453645
"##,
36463646

36473647
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:
36513650
36523651
```compile_fail
36533652
#![feature(specialization)]
@@ -3656,14 +3655,18 @@ trait SpaceLama {
36563655
fn fly(&self);
36573656
}
36583657
3658+
// applies to all T
36593659
impl<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
36633665
impl<T: Clone> SpaceLama for T {
36643666
fn fly(&self) {}
36653667
}
36663668
3669+
// since `i32` is clone, this conflicts with the previous implementation
36673670
impl 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
36813687
trait SpaceLama {
36823688
fn fly(&self);
36833689
}
36843690
3691+
// applies to all T
36853692
impl<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
36893697
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.
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
36953703
impl 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

Comments
 (0)