Skip to content

C0016 orphan-source-file

Rule: Every .rs file under src/ is reached by a mod declaration.

Code C0016 (stable, never reused)
Id orphan-source-file
Category structure
Source spirit_level
Fix by hand

Level per tier

Tier Level Reason
small off
small-workspace off
medium warn a file no mod reaches is never compiled or tested, yet reads like live code
big deny a file no mod reaches is never compiled or tested, yet reads like live code
ai off
embedded off
ui off
egui off
units-strict off
units-paranoid off

Parameters

Name Type Default Meaning
skip list of strings [] globs, relative to the package, of files that are compiled another way

Why

rustc compiles the files that mod declarations reach from a crate root and ignores every other file. A file left under src/ after a rename or a lost mod line is never built, never tested and never warned about, yet it reads like live code and agents edit it.

The lint follows mod declarations from each target root, #[path] and test-only modules included, and reports each .rs file under src/ that none reaches. A file pulled in with include! counts as reached, and so does one whose name appears in a macro call of the module file that would declare it (a macro that writes the mod lines).

How to fix

Declare the module where it belongs (mod name;), or delete the file. A file compiled another way (by a build script, a macro) goes in the skip list with a reason.

Configure

[lints.orphan-source-file]
level = "deny"
skip = []
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(orphan-source-file) <reason> (waivers); the code works there too, as in [lints.C0016].