]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0283.md
Auto merge of #66396 - smmalis37:pythontest, r=alexcrichton
[rust.git] / src / librustc_error_codes / error_codes / E0283.md
1 This error occurs when the compiler doesn't have enough information
2 to unambiguously choose an implementation.
3
4 For example:
5
6 ```compile_fail,E0283
7 trait Generator {
8     fn create() -> u32;
9 }
10
11 struct Impl;
12
13 impl Generator for Impl {
14     fn create() -> u32 { 1 }
15 }
16
17 struct AnotherImpl;
18
19 impl Generator for AnotherImpl {
20     fn create() -> u32 { 2 }
21 }
22
23 fn main() {
24     let cont: u32 = Generator::create();
25     // error, impossible to choose one of Generator trait implementation
26     // Should it be Impl or AnotherImpl, maybe something else?
27 }
28 ```
29
30 To resolve this error use the concrete type:
31
32 ```
33 trait Generator {
34     fn create() -> u32;
35 }
36
37 struct AnotherImpl;
38
39 impl Generator for AnotherImpl {
40     fn create() -> u32 { 2 }
41 }
42
43 fn main() {
44     let gen1 = AnotherImpl::create();
45
46     // if there are multiple methods with same name (different traits)
47     let gen2 = <AnotherImpl as Generator>::create();
48 }
49 ```