Email me

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.rs or src/foo/mod.rs (relative to the file that declares it).
  • Declaring a submodule from src/bar.rs: Rust looks in src/bar/foo.rs, not src/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.rs

2. 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

E0583Names, paths and imports
Activein rustc 1.99.0
8related errors linked below

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

All 518 Rust error codes · Rust crate data · Glossary

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?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ