Email me

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.

E0659Everything else
Activein rustc 1.99.0
8related errors linked below

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

All 518 Rust error codes · Rust crate data · Glossary

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?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ