Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

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.

~4 min readRust
#rust#modules#visibility#compiler-errors
Bold white headline reading E0432 beside a cyan Rust module crate missing an amber path link.

Introduction & Quick Summary

Rust points at an import that will not resolve:

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

rust
// 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 }
rust
// src/routes.rs use crate::models::User; // now resolves

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

bash
cargo new --lib import-demo && cd import-demo mkdir -p src/models src/routes
rust
// src/lib.rs pub mod models; pub mod routes;
rust
// src/models/mod.rs pub struct User { pub id: u64 } mod private_db; // private module: not reachable from outside
rust
// src/routes/mod.rs use crate::models::User; // ok use crate::models::private_db::Conn; // error[E0432]: module `private_db` is private
Path formStarts fromTypical use
crate::models::Usercrate rootabsolute inside the crate
self::helpercurrent modulesibling item
super::models::Userparent modulenested child modules
models::User2018+ crate namedependency crate
::models::Userextern preludeexplicit external crate
crate::models::*glob importpreludes, test helpers
E0432 detail lineMeaningFix
no 'User' in 'models'item not defined therecorrect name, or add the struct
module 'models' is privatemod not pubmake each level pub
unresolved import 'crate::models'module not declaredmod models; at the parent
could not find 'models' in 'crate'feature flag offenable the feature or add #[cfg] guard
no 'x' in the rootitem in another modulefix the path
the crate 'x' has no item named 'y'version differencecheck the docs for that version

Key Comparison Table

ErrorSubjectFix location
E0432use path inside the cratemodule tree and visibility
E0433external crate not foundCargo.toml dependencies
E0412type name not in scopeimport or define the type
E0425value not in scopeimport or bind the value
E0603module or item is privateadd pub on the right level
warning: unused importimport exists but unusedremove it, or use #[allow]
warning: ambiguous glob re-exporttwo globs provide the same nameimport explicitly
VisibilityVisible in current moduleVisible in childrenVisible outside crate
(none)yesnono
pub(crate)yesyesno
pub(super)yesvia parent onlyno
pub(in crate::models)yesinside that subtreeno
pubyesyesyes, if the path is public
pub use re-exportyesyesyes, at the new path

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. The module was never declared

rust
// 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

rust
// src/lib.rs mod models; // private module // src/models.rs pub struct User; // public item inside a private module
rust
// src/routes.rs use crate::models::User; // E0432: module `models` is private

Every 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

rust
// src/models/user.rs use super::Role; // parent module (models) use crate::db::Conn; // crate root

Inside 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

rust
#[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

rust
// src/lib.rs mod models; pub use models::User; // facade at crate root // downstream use import_demo::User; // works without exposing the module path

pub 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

toml
[dependencies] serde = { version = "1", features = ["derive"] }
rust
use serde::Serialize; // dependency import

A 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 opens src/models/user.rs unless a parent declares mod user;. Editors create the file and stop there.
  • pub only on the item. Visibility must hold at every level of the path; a public struct inside a private module is unreachable from outside.
  • Using super from the crate root. super at the root has nowhere to go and produces an unresolved import; use crate::.
  • Mixing 2015 and 2018 path rules. In the 2015 edition, use models::User; at the root means a crate-relative path only with crate:: or self::; in 2018 and later, a bare name means an external crate. Copying snippets between editions produces confusing E0432 errors.
  • extern crate in 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 -p for that package alone.
  • Edition 2024. unsafe extern blocks 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 of use crate::...; an E0432 in a doc test with a green cargo build points 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 documentation

The Rust documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Rust work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Rust guides

More in Rust

All Rust guides

The guides filed next to this one in Rust, in library order.