Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0433: failed to resolve
What it meansA path does not resolve: a type, module or crate is used without being imported or declared.
What rustc prints
error[E0433]: cannot find type `HashMap` in this scope --> main.rs:3:11 | 3 | let map = HashMap::new(); | ^^^^^^^ use of undeclared type `HashMap` | help: consider importing this struct | 2 + use std::collections::HashMap; |
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.
Why it happens
HashMaporHashSetused withoutuse std::collections::HashMap;.- A crate used in code but not listed in Cargo.toml.
- A module file that is not declared with
mod.
How to fix it
1. Add the import
use std::collections::HashMap;2. Add the dependency
Then use its path.
cargo add serde --features derive3. Declare the module
In main.rs or lib.rs.
mod parser;
use parser::parse;Other wordings of this error
failed to resolve, use of undeclared type, use of undeclared crate or module, cannot find type in this scope
The compiler team's explanation
An undeclared crate, module, or type was used.
Erroneous code example:
let map = HashMap::new();
// error: failed to resolve: use of undeclared type `HashMap`
Please verify you didn't misspell the type/module's name or that you didn't forget to import it:
use std::collections::HashMap; // HashMap has been imported.
let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
If you've expected to use a crate name:
use ferris_wheel::BigO;
// error: failed to resolve: use of undeclared module or unlinked crate
Make sure the crate has been added as a dependency in Cargo.toml.
To use a module from your current crate, add the crate:: prefix to the path.
From rustc --explain E0433 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0282type annotations needed
- E0422cannot find struct, variant or union type `Foo` in this scope
- E0428the name `Bar` is defined multiple times
- E0434can't capture dynamic environment in a fn item
- E0437type `Bar` is not a member of trait `Foo`
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?