File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ An associated function for a trait was defined to be static, but an
2
2
implementation of the trait declared the same function to be a method (i.e., to
3
3
take a ` self ` parameter).
4
4
5
- Here's an example of this error :
5
+ Erroneous code example:
6
6
7
7
``` compile_fail,E0185
8
8
trait Foo {
@@ -17,3 +17,19 @@ impl Foo for Bar {
17
17
fn foo(&self) {}
18
18
}
19
19
```
20
+
21
+ When a type implements a trait's associated function, it has to use the same
22
+ signature. So in this case, since ` Foo::foo ` doesn't take argument and doesn't
23
+ return anything, its implementation on ` Bar ` should the same:
24
+
25
+ ```
26
+ trait Foo {
27
+ fn foo();
28
+ }
29
+
30
+ struct Bar;
31
+
32
+ impl Foo for Bar {
33
+ fn foo() {} // ok!
34
+ }
35
+ ```
You can’t perform that action at this time.
0 commit comments