Email me

Rust errors / Names, paths and imports

Rust compiler error · checked with rustc 1.99.0

Rust error E0034: multiple applicable items in scope

What it meansThe compiler doesn't know what method to call because more than one method has the same prototype.

What rustc prints

error[E0034]: multiple applicable items in scope
  --> main.rs:15:11
   |
15 |     Test::foo() // error, which foo() to call?
   |           ^^^ multiple `foo` found
   |
note: candidate #1 is defined in an impl of the trait `Trait1` for the type `Test`
  --> main.rs:11:24
   |
11 | impl Trait1 for Test { fn foo() {} }
   |                        ^^^^^^^^
note: candidate #2 is defined in an impl of the trait `Trait2` for the type `Test`
  --> main.rs:12:24
   |
12 | impl Trait2 for Test { fn foo() {} }
   |                        ^^^^^^^^
help: use fully-qualified syntax to disambiguate
   |
15 -     Test::foo() // error, which foo() to call?
15 +     <Test as Trait1>::foo() // error, which foo() to call?
   |
15 -     Test::foo() // error, which foo() to call?
15 +     <Test as Trait2>::foo() // error, which foo() to call?
   |

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.

E0034Names, paths and imports
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

The compiler doesn't know what method to call because more than one method has the same prototype.

Erroneous code example:

struct Test;

trait Trait1 {
    fn foo();
}

trait Trait2 {
    fn foo();
}

impl Trait1 for Test { fn foo() {} }
impl Trait2 for Test { fn foo() {} }

fn main() {
    Test::foo() // error, which foo() to call?
}

To avoid this error, you have to keep only one of them and remove the others. So let's take our example and fix it:

struct Test;

trait Trait1 {
    fn foo();
}

impl Trait1 for Test { fn foo() {} }

fn main() {
    Test::foo() // and now that's good!
}

However, a better solution would be using fully explicit naming of type and trait:

struct Test;

trait Trait1 {
    fn foo();
}

trait Trait2 {
    fn foo();
}

impl Trait1 for Test { fn foo() {} }
impl Trait2 for Test { fn foo() {} }

fn main() {
    <Test as Trait1>::foo()
}

One last example:

trait F {
    fn m(&self);
}

trait G {
    fn m(&self);
}

struct X;

impl F for X { fn m(&self) { println!("I am F"); } }
impl G for X { fn m(&self) { println!("I am G"); } }

fn main() {
    let f = X;

    F::m(&f); // it displays "I am F"
    G::m(&f); // it displays "I am G"
}

From rustc --explain E0034 (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 nextE0425: cannot find value in this scopeA 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