]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_error_codes/src/error_codes/E0186.md
New upstream version 1.68.2+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0186.md
CommitLineData
60c5eb7d
XL
1An associated function for a trait was defined to be a method (i.e., to take a
2`self` parameter), but an implementation of the trait declared the same function
3to be static.
4
dfeec247 5Erroneous code example:
60c5eb7d
XL
6
7```compile_fail,E0186
8trait Foo {
9 fn foo(&self);
10}
11
12struct Bar;
13
14impl Foo for Bar {
15 // error, method `foo` has a `&self` declaration in the trait, but not in
16 // the impl
17 fn foo() {}
18}
19```
dfeec247
XL
20
21When a type implements a trait's associated function, it has to use the same
22signature. So in this case, since `Foo::foo` takes `self` as argument and
23does not return anything, its implementation on `Bar` should be the same:
24
25```
26trait Foo {
27 fn foo(&self);
28}
29
30struct Bar;
31
32impl Foo for Bar {
33 fn foo(&self) {} // ok!
34}
35```