]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0201.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0201.md
1 Two associated items (like methods, associated types, associated functions,
2 etc.) were defined with the same identifier.
3
4 Erroneous code 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 ```