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