Email me

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

  • HashMap or HashSet used without use 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 derive

3. 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

E0433Types and traits
Activein rustc 1.99.0
8related errors linked below

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

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0308: mismatched typesA 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