E0583 rust build_error ai_generated true

error[E0583]: file not found for module `module_name`

ID: rust/e0583-file-not-found-for-module

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
rustc 1.68.0 active
rustc 1.70.0 active
rustc 1.74.0 active

Root Cause

Rust cannot find the source file for a declared module, either because the file path is incorrect, the file extension is wrong, or the module is not properly declared in `mod.rs` or `lib.rs`.

generic

中文

Rust 找不到声明的模块的源文件,可能是因为文件路径错误、文件扩展名错误,或者模块未在 `mod.rs` 或 `lib.rs` 中正确声明。

Official Documentation

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

Workarounds

  1. 95% success Ensure the module file is created with the correct name and path: for `mod module_name;` in `src/lib.rs`, create `src/module_name.rs`.
    Ensure the module file is created with the correct name and path: for `mod module_name;` in `src/lib.rs`, create `src/module_name.rs`.
  2. 90% success If the module has submodules, create a directory `src/module_name/` with a `mod.rs` file inside.
    If the module has submodules, create a directory `src/module_name/` with a `mod.rs` file inside.
  3. 85% success Check for typos in the `mod` declaration and the file name, ensuring they match exactly (case-sensitive).
    Check for typos in the `mod` declaration and the file name, ensuring they match exactly (case-sensitive).

中文步骤

  1. Ensure the module file is created with the correct name and path: for `mod module_name;` in `src/lib.rs`, create `src/module_name.rs`.
  2. If the module has submodules, create a directory `src/module_name/` with a `mod.rs` file inside.
  3. Check for typos in the `mod` declaration and the file name, ensuring they match exactly (case-sensitive).

Dead Ends

Common approaches that don't work:

  1. 50% fail

    Rust expects module files to follow a specific naming convention based on the `mod` declaration; wrong placement won't be recognized.

  2. 40% fail

    Rustc only recognizes `.rs` files for module declarations; other extensions are ignored.