Rust errors / Names, paths and imports
Rust compiler error · checked with rustc 1.99.0
Rust error E0583: file not found for module
What it meansA mod foo; line tells Rust to load the module from a file, and that file is not where Rust looks.
What rustc prints
error[E0583]: file not found for module `file_that_doesnt_exist` --> main.rs:1:1 | 1 | mod file_that_doesnt_exist; // error: file not found for module | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: to create the module `file_that_doesnt_exist`, create file "file_that_doesnt_exist.rs" or "file_that_doesnt_exist\mod.rs" = note: if there is a `mod file_that_doesnt_exist` elsewhere in the crate already, import it with `use crate::...` instead
Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
Why it happens
- The file is not at
src/foo.rsorsrc/foo/mod.rs(relative to the file that declares it). - Declaring a submodule from
src/bar.rs: Rust looks insrc/bar/foo.rs, notsrc/foo.rs. - A typo or a hyphen in the file name (use underscores).
How to fix it
1. Put the file where Rust looks
For mod foo; in main.rs or lib.rs.
src/main.rs // mod foo;
src/foo.rs // the module
src/foo/bar.rs // mod bar; inside foo.rs2. Or point at the file
Rarely needed, but works for odd layouts.
#[path = "generated/foo.rs"]
mod foo;Other wordings of this error
file not found for module, to create the module, create file
The compiler team's explanation
A file wasn't found for an out-of-line module.
Erroneous code example:
mod file_that_doesnt_exist; // error: file not found for module
fn main() {}
Please be sure that a file corresponding to the module exists. If you want to use a module named file_that_doesnt_exist, you need to have a file named file_that_doesnt_exist.rs or file_that_doesnt_exist/mod.rs in the same directory.
From rustc --explain E0583 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
Up next
Often hit nextE0425: cannot find value in this scopeA related error from the same family.Read it next →Did this answer your question?