E0433 rust module_error ai_generated true

error[E0433]: failed to resolve: use of undeclared crate or module `my_crate` --> src/main.rs:2:5 | 2 | use my_crate::some_module; | ^^^^^^^^ use of undeclared crate or module `my_crate`

ID: rust/e0433-module-not-found-workspace

Also available as: JSON · Markdown · 中文
93%Fix Rate
88%Confidence
1Evidence
2023-07-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
rustc 1.73 active
cargo 1.73 active

Root Cause

Attempting to use a crate that is not listed as a dependency in `Cargo.toml`, or a module that is not declared via `mod`.

generic

中文

尝试使用一个未在 `Cargo.toml` 中列为依赖的 crate,或未通过 `mod` 声明的模块。

Official Documentation

https://doc.rust-lang.org/stable/error_codes/E0433.html

Workarounds

  1. 95% success Add the missing crate to `Cargo.toml`: `my_crate = "1.0"` and run `cargo build`.
    Add the missing crate to `Cargo.toml`: `my_crate = "1.0"` and run `cargo build`.
  2. 90% success If it's a local module, declare it with `mod my_module;` in `main.rs` or `lib.rs`.
    If it's a local module, declare it with `mod my_module;` in `main.rs` or `lib.rs`.

中文步骤

  1. 将缺失的 crate 添加到 `Cargo.toml`:`my_crate = "1.0"` 并运行 `cargo build`。
  2. 如果是本地模块,在 `main.rs` 或 `lib.rs` 中使用 `mod my_module;` 声明它。

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Cargo cannot find the crate; no matching package available.

  2. 80% fail

    In Rust 2018+, `extern crate` is rarely needed and still requires the crate to be in dependencies.