Rust E0432: unresolved import
E0432 is a module graph problem: a missing mod declaration, a private parent or a wrong path. Fix the tree, not the dependency list.

Introduction & Quick Summary
Rust points at an import that will not resolve:
error[E0432]: unresolved import `crate::models::User`
--> src/routes.rs:3:5
|
3 | use crate::models::User;
| ^^^^^^^^^^^^^^^ no `User` in `models`Quick answer: the path names something the compiler cannot find at that location. Either the module is not declared, the item is not public, or the path is wrong for the current module tree.
// src/lib.rs or src/main.rs
pub mod models; // required once, at the crate root
// src/models.rs
pub struct User { pub id: u64 }// src/routes.rs
use crate::models::User; // now resolvesE0432 is about the module graph, not about dependencies; a missing crate produces E0433 instead. That distinction saves time: E0432 means fix mod, pub or the path, while E0433 means fix Cargo.toml or extern crate. This guide walks the module tree, the four common causes, and the re-export patterns that make large crates usable.
Core Mechanics, Signatures & Reproducible Setup
Since the 2018 edition, paths in use start from a crate name, crate, self or super. A module becomes part of the tree only when a parent declares it with mod, and an item is visible to another module only when its module chain is public.
cargo new --lib import-demo && cd import-demo
mkdir -p src/models src/routes// src/lib.rs
pub mod models;
pub mod routes;// src/models/mod.rs
pub struct User { pub id: u64 }
mod private_db; // private module: not reachable from outside// src/routes/mod.rs
use crate::models::User; // ok
use crate::models::private_db::Conn; // error[E0432]: module `private_db` is private| Path form | Starts from | Typical use |
|---|---|---|
crate::models::User | crate root | absolute inside the crate |
self::helper | current module | sibling item |
super::models::User | parent module | nested child modules |
models::User | 2018+ crate name | dependency crate |
::models::User | extern prelude | explicit external crate |
crate::models::* | glob import | preludes, test helpers |
| E0432 detail line | Meaning | Fix |
|---|---|---|
no 'User' in 'models' | item not defined there | correct name, or add the struct |
module 'models' is private | mod not pub | make each level pub |
unresolved import 'crate::models' | module not declared | mod models; at the parent |
could not find 'models' in 'crate' | feature flag off | enable the feature or add #[cfg] guard |
no 'x' in the root | item in another module | fix the path |
the crate 'x' has no item named 'y' | version difference | check the docs for that version |
Key Comparison Table
| Error | Subject | Fix location |
|---|---|---|
| E0432 | use path inside the crate | module tree and visibility |
| E0433 | external crate not found | Cargo.toml dependencies |
| E0412 | type name not in scope | import or define the type |
| E0425 | value not in scope | import or bind the value |
| E0603 | module or item is private | add pub on the right level |
| warning: unused import | import exists but unused | remove it, or use #[allow] |
| warning: ambiguous glob re-export | two globs provide the same name | import explicitly |
| Visibility | Visible in current module | Visible in children | Visible outside crate |
|---|---|---|---|
| (none) | yes | no | no |
pub(crate) | yes | yes | no |
pub(super) | yes | via parent only | no |
pub(in crate::models) | yes | inside that subtree | no |
pub | yes | yes | yes, if the path is public |
pub use re-export | yes | yes | yes, at the new path |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. The module was never declared
// src/lib.rs
pub mod routes;
// forgetting this line
// pub mod models;
// src/routes/mod.rs
use crate::models::User; // E0432: unresolved import `crate::models`Adding mod models; to the crate root puts the module into the tree; src/models.rs or src/models/mod.rs must exist. A file that exists but is never declared is invisible to the compiler, which is why "the file is right there" is the least useful observation during debugging.
2. Missing pub on one level
// src/lib.rs
mod models; // private module
// src/models.rs
pub struct User; // public item inside a private module// src/routes.rs
use crate::models::User; // E0432: module `models` is privateEvery segment of the path must be visible from the importing module. pub mod models; fixes the module level; if User itself lacked pub, the error would say struct 'User' is private or become E0603 on direct use.
3. The right path for the module you are in
// src/models/user.rs
use super::Role; // parent module (models)
use crate::db::Conn; // crate rootInside models::user, crate::models::user::Role compiles only if Role is declared in that same module. super::Role is shorter and survives moving the module. In a binary crate, crate refers to main.rs; in a library, to lib.rs; a project with both has two roots, and an item in main.rs is not reachable from lib.rs.
4. Feature flags and conditional compilation
#[cfg(feature = "postgres")]
pub mod pg;
#[cfg(feature = "postgres")]
use crate::db::pg::Pool;If the feature is off, the module does not exist and the import fails. Either enable it in Cargo.toml (features = ["postgres"]) or guard the import with the same cfg. A dependency with default-features = false can also remove a module the code expects.
5. Re-exports and public facades
// src/lib.rs
mod models;
pub use models::User; // facade at crate root
// downstream
use import_demo::User; // works without exposing the module pathpub use is how crates keep internals private while offering a stable path. A glob re-export (pub use models::*;) is convenient and produces ambiguous-name errors when two modules export the same symbol; prefer explicit names in public APIs. Use the diff checker to compare module trees between branches, and the regex tester to find every use crate:: path that still points at a moved module.
6. Dependencies, workspaces and path confusion
[dependencies]
serde = { version = "1", features = ["derive"] }use serde::Serialize; // dependency importA missing dependency gives E0433: failed to resolve: use of undeclared crate or module 'serde', not E0432. In a workspace, use other_crate::Thing; needs other_crate in [dependencies] even though it is in the same repository. A dependency renamed with package = "..." must be imported under the alias.
Common Compilation/Runtime Mistakes & Version Gotchas
- Creating the file without
mod. The compiler never openssrc/models/user.rsunless a parent declaresmod user;. Editors create the file and stop there. pubonly on the item. Visibility must hold at every level of the path; a public struct inside a private module is unreachable from outside.- Using
superfrom the crate root.superat the root has nowhere to go and produces an unresolved import; usecrate::. - Mixing 2015 and 2018 path rules. In the 2015 edition,
use models::User;at the root means a crate-relative path only withcrate::orself::; in 2018 and later, a bare name means an external crate. Copying snippets between editions produces confusing E0432 errors. extern cratein the 2018 edition. It is unnecessary and can shadow a module name; remove it.- Feature unification surprises. A workspace member enabling a feature makes it visible to another member at build time and not in
cargo check -pfor that package alone. - Edition 2024.
unsafe externblocks and other changes affect FFI declarations; paths and visibility rules are unchanged, but generated bindings may need regeneration. - Doc tests. Examples in doc comments compile as separate crates and often need
use mycrate::...instead ofuse crate::...; an E0432 in a doc test with a greencargo buildpoints there.
Read E0432 as a map question: which module am I in, which module am I naming, and is every hop public and declared. That model answers the error faster than editing paths by trial.
Official documentation: the E0432 error index and Cargo dependency specification.
Official references
primary documentationThe Rust documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Rust work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Rust guides
All Rust guidesRust E0282: type annotations needed
E0282 means inference ran out of information. Annotate the binding, add a turbofish to collect or parse, or fix the signature the value flows into.
Rust E0463: can't find crate for std
The target triple has no standard library installed. Add the target with rustup, check the target string and link the right ABI.
Rust E0106: missing lifetime specifier
E0106 appears when a returned borrow has no input to borrow from. Name the lifetime in functions, structs and impls, or return owned data.
Rust E0597: borrowed value does not live long enough
E0597 says a borrow outlives the value it points at. Reorder the declarations, own the data, or annotate a lifetime only when the holder truly borrows.
More in Rust
All Rust guidesThe guides filed next to this one in Rust, in library order.