]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0201.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0201.md
CommitLineData
dfeec247
XL
1Two associated items (like methods, associated types, associated functions,
2etc.) were defined with the same identifier.
60c5eb7d 3
dfeec247 4Erroneous code example:
60c5eb7d
XL
5
6```compile_fail,E0201
7struct Foo(u8);
8
9impl Foo {
10 fn bar(&self) -> bool { self.0 > 5 }
11 fn bar() {} // error: duplicate associated function
12}
13
14trait Baz {
15 type Quux;
16 fn baz(&self) -> bool;
17}
18
19impl Baz for Foo {
20 type Quux = u32;
21
22 fn baz(&self) -> bool { true }
23
24 // error: duplicate method
25 fn baz(&self) -> bool { self.0 > 5 }
26
27 // error: duplicate associated type
28 type Quux = u32;
29}
30```
31
32Note, however, that items with the same name are allowed for inherent `impl`
33blocks that don't overlap:
34
35```
36struct Foo<T>(T);
37
38impl Foo<u8> {
39 fn bar(&self) -> bool { self.0 > 5 }
40}
41
42impl Foo<bool> {
43 fn bar(&self) -> bool { self.0 }
44}
45```