rust import_error ai_generated true

error[E0433]: failed to resolve: use of undeclared crate or module

ID: rust/e0433-unresolved-import

Also available as: JSON · Markdown
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Crate or module not found. Missing dependency in Cargo.toml or wrong use path.

generic

Workarounds

  1. 95% success Add the dependency to Cargo.toml: [dependencies] section
    cargo add <crate-name>

    Sources: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html

  2. 90% success Check use path: crate:: for local, module_name:: for deps
    use crate::module::MyType;  // local
    use serde::Serialize;  // external

    Sources: https://doc.rust-lang.org/reference/items/use-declarations.html

  3. 82% success For feature-gated items, enable the feature in Cargo.toml
    serde = { version = "1", features = ["derive"] }

    Sources: https://doc.rust-lang.org/cargo/reference/features.html

Dead Ends

Common approaches that don't work:

  1. Add the path to src/lib.rs manually 75% fail

    If the crate isn't in Cargo.toml, it's not available

  2. Use extern crate (pre-2018 edition syntax) 70% fail

    Unnecessary since Rust 2018 — just add to Cargo.toml

Error Chain

Frequently confused with: