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