]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0790.md
Rollup merge of #102215 - alexcrichton:wasm-link-whole-archive, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0790.md
1 You need to specify a specific implementation of the trait in order to call the
2 method.
3
4 Erroneous code example:
5
6 ```compile_fail,E0790
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 let cont: u32 = Generator::create();
24 // error, impossible to choose one of Generator trait implementation
25 // Should it be Impl or AnotherImpl, maybe something else?
26 ```
27
28 This error can be solved by adding type annotations that provide the missing
29 information to the compiler. In this case, the solution is to use a concrete
30 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 let gen1 = AnotherImpl::create();
44
45 // if there are multiple methods with same name (different traits)
46 let gen2 = <AnotherImpl as Generator>::create();
47 ```