]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0520.md
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0520.md
1 A non-default implementation was already made on this type so it cannot be
2 specialized further. Erroneous code example:
3
4 ```compile_fail,E0520
5 #![feature(specialization)]
6
7 trait SpaceLlama {
8 fn fly(&self);
9 }
10
11 // applies to all T
12 impl<T> SpaceLlama for T {
13 default fn fly(&self) {}
14 }
15
16 // non-default impl
17 // applies to all `Clone` T and overrides the previous impl
18 impl<T: Clone> SpaceLlama for T {
19 fn fly(&self) {}
20 }
21
22 // since `i32` is clone, this conflicts with the previous implementation
23 impl SpaceLlama for i32 {
24 default fn fly(&self) {}
25 // error: item `fly` is provided by an `impl` that specializes
26 // another, but the item in the parent `impl` is not marked
27 // `default` and so it cannot be specialized.
28 }
29 ```
30
31 Specialization only allows you to override `default` functions in
32 implementations.
33
34 To fix this error, you need to mark all the parent implementations as default.
35 Example:
36
37 ```
38 #![feature(specialization)]
39
40 trait SpaceLlama {
41 fn fly(&self);
42 }
43
44 // applies to all T
45 impl<T> SpaceLlama for T {
46 default fn fly(&self) {} // This is a parent implementation.
47 }
48
49 // applies to all `Clone` T; overrides the previous impl
50 impl<T: Clone> SpaceLlama for T {
51 default fn fly(&self) {} // This is a parent implementation but was
52 // previously not a default one, causing the error
53 }
54
55 // applies to i32, overrides the previous two impls
56 impl SpaceLlama for i32 {
57 fn fly(&self) {} // And now that's ok!
58 }
59 ```