Rust errors / Everything else
Rust compiler error · checked with rustc 1.99.0
Rust error E0659: `foo` is ambiguous
What it meansAn item usage is ambiguous.
What rustc prints
error[E0659]: `foo` is ambiguous --> main.rs:15:22 | 15 | crate::collider::foo(); // ERROR: `foo` is ambiguous | ^^^ ambiguous name | = note: ambiguous because of multiple glob imports of a name in the same module note: `foo` could refer to the function imported here --> main.rs:10:13 | 10 | pub use crate::moon::*; | ^^^^^^^^^^^^^^ = help: consider adding an explicit import of `foo` to disambiguate note: `foo` could also refer to the function imported here --> main.rs:11:13 | 11 | pub use crate::earth::*; | ^^^^^^^^^^^^^^^ = help: consider adding an explicit import of `foo` to disambiguate
Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
An item usage is ambiguous.
Erroneous code example:
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:
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!
}From rustc --explain E0659 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0061this function takes N arguments but M were supplied
- E0412cannot find type in this scope
- E0515cannot return reference to local variable
- E0728await is only allowed inside async functions and blocks
- E0641cannot cast to a pointer of an unknown kind
- E0646`main` function is not allowed to have a `where` clause
- E0670Rust 2015 does not permit the use of `async fn`
- E0695unlabeled `break` inside of a labeled block
Up next
Often hit nextE0061: this function takes N arguments but M were suppliedA related error from the same family.Read it next →Did this answer your question?