]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0659.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0659.md
1 An item usage is ambiguous.
2
3 Erroneous code example:
4
5 ```compile_fail,edition2018,E0659
6 pub mod moon {
7     pub fn foo() {}
8 }
9
10 pub mod earth {
11     pub fn foo() {}
12 }
13
14 mod collider {
15     pub use crate::moon::*;
16     pub use crate::earth::*;
17 }
18
19 fn main() {
20     crate::collider::foo(); // ERROR: `foo` is ambiguous
21 }
22 ```
23
24 This error generally appears when two items with the same name are imported into
25 a module. Here, the `foo` functions are imported and reexported from the
26 `collider` module and therefore, when we're using `collider::foo()`, both
27 functions collide.
28
29 To solve this error, the best solution is generally to keep the path before the
30 item when using it. Example:
31
32 ```edition2018
33 pub mod moon {
34     pub fn foo() {}
35 }
36
37 pub mod earth {
38     pub fn foo() {}
39 }
40
41 mod collider {
42     pub use crate::moon;
43     pub use crate::earth;
44 }
45
46 fn main() {
47     crate::collider::moon::foo(); // ok!
48     crate::collider::earth::foo(); // ok!
49 }
50 ```