E0432 rust module_error ai_generated true

error[E0432]: unresolved import `crate::module::Item`

ID: rust/e0432-unresolved-import-crate

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2023-08-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
rustc 1.65.0 active — — —
rustc 1.72.0 active — — —
rustc 1.80.0 active — — —

Root Cause

The specified module or item does not exist in the crate's module tree, often due to missing `mod` declaration or incorrect path.

generic

中文

指定的模块或项在 crate 的模块树中不存在,通常是由于缺少 `mod` 声明或路径错误。

Official Documentation

https://doc.rust-lang.org/error_codes/E0432.html

Workarounds

  1. 95% success Ensure the module is declared in the crate root: add `mod module;` to `lib.rs` or `main.rs`, and create the corresponding file `src/module.rs` or directory `src/module/`.
    Ensure the module is declared in the crate root: add `mod module;` to `lib.rs` or `main.rs`, and create the corresponding file `src/module.rs` or directory `src/module/`.
  2. 85% success If the item is in a submodule, use the correct relative path: `use self::submodule::Item;` or `use super::Item;`.
    If the item is in a submodule, use the correct relative path: `use self::submodule::Item;` or `use super::Item;`.
  3. 90% success Check for typos in the module or item name and ensure the file exists with the correct casing (case-sensitive on most platforms).
    Check for typos in the module or item name and ensure the file exists with the correct casing (case-sensitive on most platforms).

中文步骤

  1. Ensure the module is declared in the crate root: add `mod module;` to `lib.rs` or `main.rs`, and create the corresponding file `src/module.rs` or directory `src/module/`.
  2. If the item is in a submodule, use the correct relative path: `use self::submodule::Item;` or `use super::Item;`.
  3. Check for typos in the module or item name and ensure the file exists with the correct casing (case-sensitive on most platforms).

Dead Ends

Common approaches that don't work:

  1. 70% fail

    The module must be declared with `mod` before re-exporting; otherwise the compiler cannot find it.

  2. 50% fail

    The `crate` keyword already refers to the root; `::crate` is redundant and may be invalid.

  3. 80% fail

    Rust requires explicit `mod` declarations in `lib.rs` or `main.rs` to include modules.