]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | An attempted implementation of a trait method has the wrong number of function |
2 | parameters. | |
3 | ||
4 | Erroneous code example: | |
5 | ||
6 | ```compile_fail,E0050 | |
7 | trait Foo { | |
8 | fn foo(&self, x: u8) -> bool; | |
9 | } | |
10 | ||
11 | struct Bar; | |
12 | ||
13 | // error: method `foo` has 1 parameter but the declaration in trait `Foo::foo` | |
14 | // has 2 | |
15 | impl Foo for Bar { | |
16 | fn foo(&self) -> bool { true } | |
17 | } | |
18 | ``` | |
19 | ||
20 | For example, the `Foo` trait has a method `foo` with two function parameters | |
21 | (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits | |
22 | the `u8` parameter. To fix this error, they must have the same parameters: | |
23 | ||
24 | ``` | |
25 | trait Foo { | |
26 | fn foo(&self, x: u8) -> bool; | |
27 | } | |
28 | ||
29 | struct Bar; | |
30 | ||
31 | impl Foo for Bar { | |
32 | fn foo(&self, x: u8) -> bool { // ok! | |
33 | true | |
34 | } | |
35 | } | |
36 | ``` |