Skip to content

Rust Error E0034: Multiple Applicable Items in Scope

E0034 means your type has two methods with the same name, one from each of two traits, and you called it the short way, like book.describe(). Rust can see both and won’t pick one for you. Nothing is broken in your types; you just have to say which trait you mean. That usually takes one line, and rustc even writes it for you. This page is part of the compiler errors guide.

error[E0034]: multiple applicable items in scope
--> src/main.rs:28:25
|
28 | println!("{}", book.describe()); // ❌ Summary's or Label's?
| ^^^^^^^^ multiple `describe` found
|
note: candidate #1 is defined in an impl of the trait `Label` for the type `Book`
--> src/main.rs:21:5
|
21 | fn describe(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl of the trait `Summary` for the type `Book`
--> src/main.rs:15:5
|
15 | fn describe(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method for candidate #1
|
28 - println!("{}", book.describe()); // ❌ Summary's or Label's?
28 + println!("{}", Label::describe(&book)); // ❌ Summary's or Label's?
|
help: disambiguate the method for candidate #2
|
28 - println!("{}", book.describe()); // ❌ Summary's or Label's?
28 + println!("{}", Summary::describe(&book)); // ❌ Summary's or Label's?
|

This is the program that produces it:

trait Summary {
fn describe(&self) -> String;
}
trait Label {
fn describe(&self) -> String;
}
struct Book {
title: String,
pages: u32,
}
impl Summary for Book {
fn describe(&self) -> String {
format!("{} ({} pages)", self.title, self.pages)
}
}
impl Label for Book {
fn describe(&self) -> String {
format!("BOOK: {}", self.title.to_uppercase())
}
}
fn main() {
let book = Book { title: String::from("Rust for Crabs"), pages: 320 };
println!("{}", book.describe()); // ❌ Summary's or Label's?
}

Read the message from top to bottom:

  1. ^^^^^^^^ under describe: “multiple describe found”. Rust looked for a method called describe on Book and found more than one.
  2. The two note: lines list the candidates: one comes from impl Label for Book (line 21), the other from impl Summary for Book (line 15). Both are real, both work, and they return different text.
  3. The two help: lines show the fix for each choice. Summary::describe(&book) means “call the describe that comes from Summary, with &book as self”.

Think of two colleagues both called Sam in one office. Shouting “Sam!” doesn’t work; you say “Sam from accounting”. Summary::describe is “Sam from accounting”.

A method call like book.describe() is a shortcut. Rust looks at the type of book, then searches its own methods and the methods of every trait that is in scope and implemented for Book. Usually that search finds exactly one match. Here it finds two, and they do different things: one prints a summary, the other prints a shelf label.

Rust could pick one by some hidden rule, like “the trait defined first”. But then adding a trait, or reordering two use lines, would quietly change what your program prints. Rust refuses to guess and asks you to say it once, in the code, where every reader can see it.

There is one exception: a method in the type’s own impl Book block always wins over a trait method with the same name, so that case never gives E0034. You can read more in Traits and in Advanced traits.

Fix 1: Call it through the trait: Trait::method(&x)

Section titled “Fix 1: Call it through the trait: Trait::method(&x)”

Choose this when you need both methods and just want to say which one each time. It’s exactly what rustc suggests. The value goes in as the first argument, with the same & the method’s &self expects:

trait Summary {
fn describe(&self) -> String;
}
trait Label {
fn describe(&self) -> String;
}
struct Book {
title: String,
pages: u32,
}
impl Summary for Book {
fn describe(&self) -> String {
format!("{} ({} pages)", self.title, self.pages)
}
}
impl Label for Book {
fn describe(&self) -> String {
format!("BOOK: {}", self.title.to_uppercase())
}
}
fn main() {
let book = Book { title: String::from("Rust for Crabs"), pages: 320 };
println!("{}", Summary::describe(&book));
println!("{}", Label::describe(&book));
}

Output:

Rust for Crabs (320 pages)
BOOK: RUST FOR CRABS
▶ Try it Yourself

If the method takes &mut self, pass &mut book. If it takes self, pass book (and it moves, just like with the dot).

Fix 2: Fully qualified syntax: <Type as Trait>::method()

Section titled “Fix 2: Fully qualified syntax: <Type as Trait>::method()”

Choose this when the clashing function has no self, like a constructor or a fn category(). Then there’s no value for Rust to look at, so Trait::category() isn’t enough: you also have to name the type. <Book as Summary>::category() reads “the category that Book has because it implements Summary”. It works for methods too:

trait Summary {
fn category() -> String;
fn describe(&self) -> String;
}
trait Label {
fn category() -> String;
}
struct Book {
title: String,
}
impl Summary for Book {
fn category() -> String { String::from("Non-fiction") }
fn describe(&self) -> String { format!("A book called {}", self.title) }
}
impl Label for Book {
fn category() -> String { String::from("Shelf B") }
}
fn main() {
let book = Book { title: String::from("Rust for Crabs") };
println!("{}", <Book as Summary>::category());
println!("{}", <Book as Label>::category());
println!("{}", <Book as Summary>::describe(&book));
}

Output:

Non-fiction
Shelf B
A book called Rust for Crabs
▶ Try it Yourself

Writing Book::category() here gives E0034 too, with the help use fully-qualified syntax to disambiguate. Writing Summary::category() alone gives a different error, E0790, because the trait still doesn’t know which type you mean.

Choose this when both traits are yours and the shared name is an accident. Two methods that do different things deserve different names, and then the short book.describe() works again. It’s often the cleanest fix:

trait Summary {
fn describe(&self) -> String;
}
trait Label {
fn label_text(&self) -> String;
}
struct Book {
title: String,
pages: u32,
}
impl Summary for Book {
fn describe(&self) -> String { format!("{} ({} pages)", self.title, self.pages) }
}
impl Label for Book {
fn label_text(&self) -> String { format!("BOOK: {}", self.title.to_uppercase()) }
}
fn main() {
let book = Book { title: String::from("Rust for Crabs"), pages: 320 };
println!("{}", book.describe());
println!("{}", book.label_text());
}

Output:

Rust for Crabs (320 pages)
BOOK: RUST FOR CRABS
▶ Try it Yourself

You can’t rename methods of traits from another crate, of course. For those, use Fix 1 or Fix 4.

Choose this when the traits live in different modules or crates. A trait’s methods only work with the dot syntax while the trait is in scope. So if a part of your code needs only one of them, import only that one there. You can even put a use inside a function, so it only applies in that function:

mod report {
pub trait Summary {
fn describe(&self) -> String;
}
}
mod shop {
pub trait Label {
fn describe(&self) -> String;
}
}
struct Book {
title: String,
}
impl report::Summary for Book {
fn describe(&self) -> String { format!("A book called {}", self.title) }
}
impl shop::Label for Book {
fn describe(&self) -> String { format!("BOOK: {}", self.title.to_uppercase()) }
}
fn print_label(book: &Book) {
use shop::Label; // only Label is in scope here
println!("{}", book.describe());
}
fn main() {
use report::Summary; // only Summary is in scope here
let book = Book { title: String::from("Rust for Crabs") };
println!("{}", book.describe());
print_label(&book);
}

Output:

A book called Rust for Crabs
BOOK: RUST FOR CRABS
▶ Try it Yourself

Notice the impl blocks write report::Summary and shop::Label in full. Implementing a trait doesn’t need a use; only the dot call does. See Modules for more on use.

Your own to_string(). Every type that implements Display already gets to_string() from the standard ToString trait. Add a trait of your own with a to_string method, and point.to_string() gives E0034, with candidate #2 is defined in an impl of the trait `ToString` for the type `T` . Fix: rename yours (pretty(), to_label()), or call Pretty::to_string(&point).

Two prelude::* imports. Libraries often offer use some_crate::prelude::*; to bring in their traits. Import two preludes that both add a draw() or render() method to the same type, and the dot call becomes ambiguous. Fix: replace one glob with only the items you use, or call Render::draw(&data).

Generic functions with two bounds. In fn show<T: Summary + Label>(item: &T), item.describe() gives E0034. Careful with rustc’s suggestion here: it offers Label::describe(&item), but item is already a reference, so that gives E0277 (the trait bound `&T: Label` is not satisfied). Write Label::describe(item) without the extra &. See Generics.

  • E0790: you called a trait function with no self, like Default::default() or Summary::category(), without saying which type.
  • E0599: the opposite problem, no method with that name was found. Often the trait isn’t imported.
  • E0277: trait bound not satisfied, for example after an extra & in Trait::method(&x).
  • E0428: the name is defined multiple times. Two items with the same name in one module, rather than two trait methods.
  • All compiler errors: the full list of error pages.

Quick check

1. Book implements Summary and Label, and both have fn describe(&self). Which line calls Label's version?

2. Both traits have fn category() -> String with no self. Which call works?

3. Book has its own impl Book { fn describe(&self) ... } and also implements Summary, which has describe too. What does book.describe() do?

Score: 0 / 3