]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0371.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0371.md
1 A trait was implemented on another which already automatically implemented it.
2
3 Erroneous code examples:
4
5 ```compile_fail,E0371
6 trait Foo { fn foo(&self) { } }
7 trait Bar: Foo { }
8 trait Baz: Bar { }
9
10 impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
11 impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
12 impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
13 impl Baz for Bar { } // Note: This is OK
14 ```
15
16 When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
17 definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
18 `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
19 definition, so it is not useful to do this.