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.
The error message
Section titled “The error message”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?}What it means
Section titled “What it means”Read the message from top to bottom:
^^^^^^^^underdescribe: “multipledescribefound”. Rust looked for a method calleddescribeonBookand found more than one.- The two
note:lines list the candidates: one comes fromimpl Label for Book(line 21), the other fromimpl Summary for Book(line 15). Both are real, both work, and they return different text. - The two
help:lines show the fix for each choice.Summary::describe(&book)means “call thedescribethat comes fromSummary, with&bookasself”.
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”.
Why Rust does this
Section titled “Why Rust does this”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.
How to fix it
Section titled “How to fix it”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 CRABSIf 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-fictionShelf BA book called Rust for CrabsWriting 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.
Fix 3: Rename one of the methods
Section titled “Fix 3: Rename one of the methods”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 CRABSYou can’t rename methods of traits from another crate, of course. For those, use Fix 1 or Fix 4.
Fix 4: Import only the trait you need
Section titled “Fix 4: Import only the trait you need”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 CrabsBOOK: RUST FOR CRABSNotice 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.
Where you’ll usually see it
Section titled “Where you’ll usually see it”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.
Related errors
Section titled “Related errors”- E0790: you called a trait function with no
self, likeDefault::default()orSummary::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
&inTrait::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
Section titled “Quick check”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
Read more
Section titled “Read more”- E0034 — Rust error codes index: the official explanation, with both fully qualified forms.
- Advanced Traits — The Rust Book: the section on fully qualified syntax, with the
Pilot,WizardandHumanexample. - Disambiguating overlapping traits — Rust by Example: a short, runnable example of two traits with a method of the same name.
- Traits — The Rust Book: defining and implementing traits, and why a trait must be in scope to use its methods.
- Method call expressions — The Rust Reference: the exact rules Rust follows to find the method behind
x.method().