Skip to content

Commit 30d7419

Browse files
authored
Rollup merge of #68157 - GuillaumeGomez:clean-up-e0186, r=Dylan-DPC
Clean up E0186 explanation r? @Dylan-DPC
2 parents 9b28218 + 34186ef commit 30d7419

File tree

1 file changed

+17
-1
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+17
-1
lines changed

src/librustc_error_codes/error_codes/E0186.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ An associated function for a trait was defined to be a method (i.e., to take a
22
`self` parameter), but an implementation of the trait declared the same function
33
to be static.
44

5-
Here's an example of this error:
5+
Erroneous code example:
66

77
```compile_fail,E0186
88
trait Foo {
@@ -17,3 +17,19 @@ impl Foo for Bar {
1717
fn foo() {}
1818
}
1919
```
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` takes `self` as argument and
23+
does not return anything, its implementation on `Bar` should be the same:
24+
25+
```
26+
trait Foo {
27+
fn foo(&self);
28+
}
29+
30+
struct Bar;
31+
32+
impl Foo for Bar {
33+
fn foo(&self) {} // ok!
34+
}
35+
```

0 commit comments

Comments
 (0)