]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0201.md
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0201.md
1 It is an error to define two associated items (like methods, associated types,
2 associated functions, etc.) with the same identifier.
3
4 For example:
5
6 ```compile_fail,E0201
7 struct Foo(u8);
8
9 impl Foo {
10 fn bar(&self) -> bool { self.0 > 5 }
11 fn bar() {} // error: duplicate associated function
12 }
13
14 trait Baz {
15 type Quux;
16 fn baz(&self) -> bool;
17 }
18
19 impl 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
32 Note, however, that items with the same name are allowed for inherent `impl`
33 blocks that don't overlap:
34
35 ```
36 struct Foo<T>(T);
37
38 impl Foo<u8> {
39 fn bar(&self) -> bool { self.0 > 5 }
40 }
41
42 impl Foo<bool> {
43 fn bar(&self) -> bool { self.0 }
44 }
45 ```