Rust
E0405 Cannot Find Trait Fix
A trait name in a bound, an impl, or a dyn type is a name like any other: the compiler has to be able to see it from the place where it is written. When it cannot, the error is E0405, cannot find trait in this scope, and the cause is almost always mundane: the trait was never defined in this program, it lives in another module or crate and was never imported, or it is spelled one letter off from its definition. Define the trait, bring it into scope with use, write its full path, or fix the spelling, and the same code compiles. This guide shows each cause and each repair, and separates the two look-alike cases that are not E0405 at all: a method call on a trait that was never imported, and a trait that the prelude already puts in scope.
Written November 27, 2026 · Tested with Rust 1.99.1 · 23 min read
- The error: a bound naming a trait that does not exist
- First fix: define the trait in scope
- Second fix: import a standard trait that is not in the prelude
- Prelude traits need no import at all
Written November 27, 2026
Tested with Rust 1.99.1
What this guide is
E0405 is the error for a trait name that is not in scope where it is used. A trait name shows up in three common places: as a bound on a generic parameter, as in T: Pretty; as the trait in an implementation, as in impl Pretty for Foo; and as a trait object type, as in &dyn Pretty. In all three places the name has to resolve, the same way a type name or a function name has to resolve. If no trait with that name is visible from that spot in the program, the compiler stops with cannot find trait, the name, in this scope.
That one sentence covers four different accidents, and each one has a different repair. The trait may not exist anywhere in the program, because the definition was never written or was deleted. It may exist in another module, or in the standard library, or in a crate the program depends on, and simply never be imported into this scope. It may be a standard trait that sits outside the prelude, so it needs an import even though it feels built in. Or the name in the bound may be a misspelling of a trait that is defined a few lines away. The sections below take the causes in that order, and the last sections separate out the cases that look like this error and are not: calling a trait method without importing the trait is E0599, adding a method the trait does not declare is E0407, and a bad import path itself is E0432.
The error: a bound naming a trait that does not exist
This function promises to print any value, as long as the value's type provides a Pretty trait. No trait named Pretty is defined anywhere in the program, and nothing is imported:
fn print_it<T: Pretty>(x: T) {
let _ = x;
}
fn main() {
print_it(1);
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0405]: cannot find trait `Pretty` in this scope
--> main.rs:1:16
|
1 | fn print_it<T: Pretty>(x: T) {
| ^^^^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0405`.
The header names the code, the trait, and the problem: error[E0405], cannot find trait Pretty in this scope. The span underlines the name in the bound and labels it not found in this scope. There is no help block in this case, because the compiler has nothing to point at: no trait with a similar name exists in the program, and no known trait by that name is waiting to be imported. When E0405 arrives with no suggestion attached, the trait itself is usually missing, and the first repair below is the one to reach for.
Read the wording closely, because it rules things out. The compiler is not saying the bound is wrong, or that i32 fails to satisfy it. It never gets that far. Name resolution runs before trait checking, and the name Pretty fails at that first step. Every E0405 fix is therefore a name fix: make a trait with that name visible at that line, or change the line to name a trait that is already visible.
First fix: define the trait in scope
If the trait is your own design and its definition was never written, write it. A trait definition in the same module puts the name in scope for every bound, implementation, and trait object in that module. Here the trait is defined, implemented for i32, and the bound from the failing program then compiles unchanged:
trait Pretty {
fn pretty(&self) -> String;
}
impl Pretty for i32 {
fn pretty(&self) -> String {
format!("value {}", self)
}
}
fn print_it<T: Pretty>(x: T) {
println!("{}", x.pretty());
}
fn main() {
print_it(42);
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
value 42
The program prints value 42 and exits with status 0. The bound T: Pretty is character-for-character the one that failed before; what changed is that a trait with that name now exists in scope, and i32 has an implementation of it, so the call in main also passes trait checking. Defining the trait cures the name error. Giving the concrete type an implementation is the separate second step, and a program that defines the trait but never implements it for the type it passes will fail later, under a different error, at the call site.
Second fix: import a standard trait that is not in the prelude
A trait does not have to be your own for this error to bite. The standard library trait Write, from std::io, is not part of the prelude, so using its name in a bound without importing it fails with the same code:
fn write_it<T: Write>(x: T) {
let _ = x;
}
fn main() {
write_it(1);
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0405]: cannot find trait `Write` in this scope
--> main.rs:1:16
|
1 | fn write_it<T: Write>(x: T) {
| ^^^^^ not found in this scope
|
help: consider importing one of these traits
|
1 + use std::fmt::Write;
|
1 + use std::io::Write;
|
1 + use core::fmt::Write;
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0405`.
This time the compiler can help, and it does: the help block says consider importing one of these traits and lists both std::fmt::Write and std::io::Write, two different traits that share one name. Pick the one the bound means. The std::io::Write trait is the byte-oriented one, the trait behind writing to files, sockets, and byte buffers. The std::fmt::Write trait is the text-oriented one, the trait behind writing formatted text into a string. Importing the wrong one silences E0405 and then fails the bound at the call site, because the type you pass implements only one of them.
With std::io::Write imported, the same bound compiles, and the generic function can call the trait's write_all method on its parameter:
use std::io::Write;
fn write_it<T: Write>(mut x: T) {
let _ = x.write_all(b"hi");
}
fn main() {
let out: Vec<u8> = Vec::new();
write_it(out);
println!("done");
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
done
The program prints done and exits with status 0. Note what the import did: it brought one name, Write, into scope, and that single act made both the bound and the method call inside the function legal. An import is the whole repair whenever the trait exists somewhere the program can reach. The definition work was already done, by the standard library in this case; the name just had to be brought to the place that uses it.
Prelude traits need no import at all
Some standard traits never produce this error, because the prelude imports them into every program automatically. The prelude is the small fixed list of names Rust puts in scope for you, and it holds the traits that almost every program uses. This bound names three of them, Clone, PartialEq, and Default, with no import anywhere in the file:
fn show<T: Clone + PartialEq + Default>(x: T) -> bool {
let y = x.clone();
y == x && y == T::default()
}
fn main() {
println!("zero clones equal: {}", show(0));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
zero clones equal: true
The program compiles and prints zero clones equal: true, and exits with status 0. Those three traits, in those positions, need no use line, and adding one is harmless but pointless. The contrast with the Write case is the whole lesson: whether a standard trait needs an import is a fact about the prelude list, not about how common the trait feels. Clone is on the list. Write is not. When a bound on a standard trait fails with E0405, the trait is almost certainly a real standard trait that sits outside the prelude, and the import in the compiler's help block is the repair.
Third fix: a trait in another module needs its path or an import
A trait defined in another module of the same program is out of scope at a use site that names it bare, even though the definition is in the same file. Here Pretty is defined, in public, inside a module named inner, and implemented there for a struct. The bound outside the module still fails:
mod inner {
pub trait Pretty {
fn pretty(&self) -> String;
}
pub struct Label(pub i32);
impl Pretty for Label {
fn pretty(&self) -> String {
format!("label {}", self.0)
}
}
}
fn print_it<T: Pretty>(x: T) {
let _ = x;
}
fn main() {
print_it(inner::Label(7));
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0405]: cannot find trait `Pretty` in this scope
--> main.rs:15:16
|
15 | fn print_it<T: Pretty>(x: T) {
| ^^^^^^ not found in this scope
|
help: consider importing this trait
|
1 + use crate::inner::Pretty;
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0405`.
The header is the same E0405, and this time the help block is exact: consider importing this trait, with the line use crate::inner::Pretty; written out in full. The compiler found the trait; it is simply not visible under its bare name at this line. Two repairs work, and they differ only in where the path is written.
The first repair writes the path at the use site, in the bound itself:
mod inner {
pub trait Pretty {
fn pretty(&self) -> String;
}
pub struct Label(pub i32);
impl Pretty for Label {
fn pretty(&self) -> String {
format!("label {}", self.0)
}
}
}
fn print_it<T: inner::Pretty>(x: T) {
println!("{}", x.pretty());
}
fn main() {
print_it(inner::Label(7));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
label 7
The second repair imports the trait once, at the top of the module that uses it, and keeps the bare name in the bound:
mod inner {
pub trait Pretty {
fn pretty(&self) -> String;
}
pub struct Label(pub i32);
impl Pretty for Label {
fn pretty(&self) -> String {
format!("label {}", self.0)
}
}
}
use inner::Pretty;
fn print_it<T: Pretty>(x: T) {
println!("{}", x.pretty());
}
fn main() {
print_it(inner::Label(7));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
label 7
Both programs print label 7 and exit with status 0. Choose the import when the trait name appears more than once in the module, which it usually does, since a bound, an implementation, and a call site tend to travel together. Choose the path in the bound when the name appears exactly once and an import line would be the only other mention. Either way, qualify the claim to the shape shown: the trait here is public, and the module is in the same crate. A private trait in another module cannot be imported at all, and no path fixes that; the trait, or the module holding it, has to be made visible first.
Fourth fix: correct a misspelled trait name
When a trait with a similar name is in scope, the compiler says so. This bound spells the trait Prety, one letter short of the Pretty trait defined directly above it:
trait Pretty {
fn pretty(&self) -> String;
}
fn print_it<T: Prety>(x: T) {
let _ = x;
}
fn main() {
print_it(1);
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0405]: cannot find trait `Prety` in this scope
--> main.rs:5:16
|
1 | trait Pretty {
| ------------ similarly named trait `Pretty` defined here
...
5 | fn print_it<T: Prety>(x: T) {
| ^^^^^
|
help: a trait with a similar name exists
|
5 | fn print_it<T: Pretty>(x: T) {
| +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0405`.
The output points both ways at once. Above the error span, the definition line is marked similarly named trait Pretty defined here, and below it the help block offers a trait with a similar name exists and shows the corrected bound. One letter is the whole bug. Take the suggestion when the trait it names is the trait you meant, which the definition's method list settles in seconds: if the named trait declares the methods the bound relies on, it is the right trait. If the similar name belongs to an unrelated trait that happens to sit nearby, the real problem is a missing definition or a missing import, and accepting the suggestion trades a clear E0405 for a confusing failure at the call site.
The same error in impl and trait object positions
The bound is the most common place to meet E0405, but the name check is the same in the other two positions, and both fail with the same code and the same wording. An implementation for a trait that is not in scope:
struct Foo;
impl Pretty for Foo {}
fn main() {
let _ = Foo;
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0405]: cannot find trait `Pretty` in this scope
--> main.rs:3:6
|
3 | impl Pretty for Foo {}
| ^^^^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0405`.
And a trait object type naming a trait that is not in scope:
fn show(x: &dyn Pretty) {
let _ = x;
}
fn main() {}
$ rustc --edition 2021 main.rs -o main.bin
error[E0405]: cannot find trait `Pretty` in this scope
--> main.rs:1:17
|
1 | fn show(x: &dyn Pretty) {
| ^^^^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0405`.
In the impl case the span sits on the trait name after impl, and in the dyn case it sits on the name after dyn, and in both cases the label is not found in this scope, exactly as in the bound case. This is the official error page's own example shape: its erroneous program is an impl SomeTrait for Foo with no trait in scope, and its stated repairs are the two used throughout this guide, import the trait or define it. Position changes nothing. Wherever a trait name is written, it must resolve in that scope, and every repair above applies in every position: define it, import it, path to it, or spell it as it is defined.
Neighboring errors: probed, not assumed
Three nearby mistakes involve traits and scope, and all three carry different codes, because different checks are doing the refusing.
The most important neighbor is the method call. Using a trait's name in a bound without importing the trait is E0405, as the Write bound above shows. Calling a trait's method without importing the trait is not E0405 at all. This program calls write_all, a method of std::io::Write, on a byte vector, with no import:
fn main() {
let mut out: Vec<u8> = Vec::new();
out.write_all(b"hi").unwrap();
println!("wrote {}", out.len());
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0599]: no method named `write_all` found for struct `Vec<u8>` in the current scope
--> main.rs:3:9
|
3 | out.write_all(b"hi").unwrap();
| ^^^^^^^^^
|
::: /home/droopy/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/io/write.rs:214:8
|
214 | fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
| --------- the method is available for `Vec<u8>` here
|
= help: items from traits can only be used if the trait is in scope
help: trait `Write` which provides `write_all` is implemented but not in scope; perhaps you want to import it
|
1 + use std::io::Write;
|
help: there is a method `write` with a similar name
|
3 - out.write_all(b"hi").unwrap();
3 + out.write(b"hi").unwrap();
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0599`.
The code is E0599: no method named write_all found for struct Vec<u8> in the current scope. Read the help carefully, because it proves the trait itself is fine: items from traits can only be used if the trait is in scope, and trait Write which provides write_all is implemented but not in scope; perhaps you want to import it, with the line use std::io::Write; supplied. The type does implement the trait. The method exists. The trait is just not in scope at the call, and a method call reports that as a missing method, not as a missing trait name. Adding the import the help names fixes it:
use std::io::Write;
fn main() {
let mut out: Vec<u8> = Vec::new();
out.write_all(b"hi").unwrap();
println!("wrote {}", out.len());
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
wrote 2
The fixed program prints wrote 2 and exits with status 0, the 2 being the two bytes of the text it wrote. So the same missing import produces two different errors depending on how the trait is used: name the trait, in a bound, an implementation, or a trait object, and the error is E0405; use only its methods, and the error is E0599. When a search for the method name lands you on an E0405 page, or a search for the trait name lands you on an E0599 page, this split is why. Fix the import either way, but expect the code that matches the use you actually made.
The second neighbor is the implementation that adds a method the trait never declared. Here the trait is in scope and the implementation names it correctly, but the implementation also defines a method named extra that is not part of the trait:
trait Pretty {
fn pretty(&self) -> String;
}
struct Label(i32);
impl Pretty for Label {
fn pretty(&self) -> String {
format!("label {}", self.0)
}
fn extra(&self) -> String {
String::from("extra")
}
}
fn main() {
let label = Label(7);
println!("{}", label.pretty());
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0407]: method `extra` is not a member of trait `Pretty`
--> main.rs:12:5
|
12 | / fn extra(&self) -> String {
13 | | String::from("extra")
14 | | }
| |_____^ not a member of trait `Pretty`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0407`.
The code is E0407: method extra is not a member of trait Pretty. Nothing is missing from scope in this program; the trait is right there. The rule doing the refusing is that an implementation may only provide the items its trait declares. Either declare the method in the trait, or move it into an inherent implementation of the struct, written as impl Label with no trait named. Do not confuse this with E0405: if the trait name itself cannot be found, adding or removing methods changes nothing, because the compiler never reaches the point of comparing them.
The third neighbor is the import that cannot be resolved. When the use line itself names something that does not exist at that path, the error is E0432, reported at the import, before any bound is checked:
use std::collections::HashMapp;
fn main() {
let _map: HashMapp<String, i32> = HashMapp::new();
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0432]: unresolved import `std::collections::HashMapp`
--> main.rs:1:5
|
1 | use std::collections::HashMapp;
| ^^^^^^^^^^^^^^^^^^--------
| |
| no `HashMapp` in `collections`
|
help: a similar name exists in the module
|
1 - use std::collections::HashMapp;
1 + use std::collections::HashMap;
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0432`.
The header reads unresolved import, the span says there is no HashMapp in collections, and the help offers the similar name that does exist, HashMap. This is the import-side mirror of the misspelling case: the name is wrong, but because the wrong name sits in a use line, the code is E0432 rather than E0405. The practical difference is where to look. An E0405 with a similar-name suggestion points at the bound and at the definition. An E0432 points at the import line and at the module being imported from. Fix the name in the place the span underlines.
The exact rule: a trait name must resolve in the scope where it is written
The official page for E0405 opens with the rule in one sentence: a trait that is not in scope was used. Its advice is to verify that the name of the trait was not misspelled and to ensure that it was imported, and its corrected example gives the same two repairs this guide uses: import the trait with a use line, or define the trait. Its erroneous example is the impl position, an implementation naming a trait that is not in scope, which the impl probe above reproduces under this compiler with the same code.
The Reference's page on traits states where a trait definition lives: the trait declaration defines a trait in the type namespace of the module or block where it is located. That sentence is the mechanism behind the module case. A trait defined inside inner is a name in that module's namespace, so a bare use of the name outside the module has nothing to resolve to until a path or an import connects the two scopes. The same page notes that generic items may use traits as bounds on their type parameters, which is the bound position: a bound is a use of the trait's name, and it obeys the same resolution rule as any other use.
The standard library's page on the prelude explains the one exception class. The prelude is the list of things Rust automatically imports into every program, it is kept as small as possible, and it is focused on things, particularly traits, which are used in almost every program. Its contents list includes the Clone trait, the comparison traits including PartialEq, and the Default trait, the three traits in the no-import probe above, and it does not include Write, from either std::io or std::fmt. That list, and nothing else, is what separates a standard trait that needs an import from one that does not.
The fixes, ranked
- First, import the trait with a
useline at the top of the module that uses its name. This is the repair whenever the trait already exists, in the standard library, in a crate the program depends on, or in another module of the same program, and it is the repair the compiler's own help proposes in the module and standard trait cases above. - Second, write the trait's full path at the use site, as in the bound
T: inner::Pretty. This is the right shape when the name appears once, or when two traits with the same name are in play and the path is what tells them apart, as it does for the two standard traits namedWrite. - Third, define the trait, when no trait by that name exists anywhere the program can reach. A definition in the same module puts the name in scope for the whole module; remember that defining the trait and implementing it for a concrete type are two steps, and the bound needs both before a call compiles.
- Fourth, correct the spelling, when the compiler offers a similar name and the trait it names declares the methods the bound relies on. Check the named trait's methods before accepting, so a nearby unrelated trait is not adopted by accident.
- Before choosing any of these, confirm the code really is E0405. A method call that fails for a missing trait import is E0599, an extra method in an implementation is E0407, and a bad path in a
useline is E0432, and each of those is repaired at a different place.
Which fix for which cause
- Trait bound, implementation, or trait object names a trait defined nowhere in the program: E0405 with no help block. Define the trait in the module, then implement it for the types the bound is used with.
- Bound names a standard trait outside the prelude, such as
Write: E0405 with a help block listing the traits to import. Import the one the bound means;std::io::Writeandstd::fmt::Writeare different traits. - Trait is defined in another module of the same program and used bare outside it: E0405 with a help block giving the full
useline. Import it, or write its path in the bound. - Bound misspells a trait that is defined in scope: E0405 with a similar-name suggestion naming the defined trait. Correct the spelling, after confirming the suggested trait declares the methods the bound needs.
- Bound names a prelude trait such as
Clone,PartialEq, orDefault: no error. These names are in scope in every program, and no import is needed or useful. - A trait method is called but the trait was never imported: E0599, no method named, with help stating the trait is implemented but not in scope. Import the trait; the error is about the method lookup, not the trait name.
- An implementation defines a method its trait does not declare: E0407, method is not a member of the trait. Declare the method in the trait, or move it to an inherent implementation of the type.
- A
useline names an item that does not exist at that path: E0432, unresolved import. Fix the name or the path in the import line itself.
Checklist
- Read the help block before anything else. No help block at all usually means the trait is defined nowhere; a list of traits to import means the trait is standard or in a crate; a single full
useline means the trait is in another module of this program; a similar-name note means a spelling is off. - Decide whether the trait should exist. If it is your own design and was never defined, no import will save the bound; write the definition first.
- When the compiler lists two traits with one name, as it does for
Write, pick by the methods the code calls, not by the order of the list. Byte output meansstd::io::Write; formatted text into a string meansstd::fmt::Write. - Do not add imports for prelude traits. If a bound on
CloneorDefaultfails, the cause is something else in the program, because those names are already in scope. - Check which use failed. A trait name in a bound, an implementation, or a trait object gives E0405; a method call gives E0599; an implementation with an extra method gives E0407; a wrong name inside a
useline gives E0432. - After the fix, run the program, not just the compiler. The fixed programs in this guide print the value the bound made usable, and that output line is the proof the trait is not only in scope but implemented for the type being passed.
Related guides on this site
- E0412 Cannot Find Type Fix
- E0422 Cannot Find Struct Fix
- E0425 Cannot Find Value Fix
- E0185 Method Has Self but Trait Does Not Fix
Sources
- Rust Compiler Error Index, E0405 — for the trait not being in scope, for verifying the spelling and ensuring the trait was imported, and for the two repairs of importing the trait or defining it.
- The Rust Reference, Traits — for a trait declaration defining the trait in the type namespace of the module or block where it is located, and for generic items using traits as bounds on their type parameters.
- The Rust Standard Library, Prelude — for the prelude being the list of things Rust automatically imports into every program, for it being kept as small as possible and focused on traits used in almost every program, and for its contents including Clone, PartialEq, and Default.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.