Should a .rs file have a size limit?
Question: What do existing Rust best-practice sources say about how large a
single .rs file should be — and does any of it mechanically guard against a
37,799-line file?
Date: 2026-12-06
TL;DR
No primary Rust source sets a maximum file size. The only mechanical size rule
in the ecosystem is clippy::too_many_lines — 100 code lines per function,
in the pedantic group, allow-by-default — and DropTerm never enables it. The
Book's testing chapter prescribes inline #[cfg(test)] mod tests in every
source file, which is where most of DropTerm's bulk sits. File-level size has no
upstream guard at all: app_shell.rs at 37,799 lines breaks no Rust rule,
because no Rust rule exists.
Findings
1. No official Rust source caps file or module size
The Rust Style Guide (rust-lang/rust, src/doc/style-guide/src) has nine
chapters: SUMMARY, advice, cargo, editions, expressions, items,
nightly, principles, statements, types. Searching advice.md,
principles.md, and items.md for file-size, module-size, or splitting
guidance returns nothing. The Rust API Guidelines checklist has no guideline
about physical source length or module size; its structural items concern API
shape (private fields, newtypes), not file organization. This is rule
absence, not an unenforced rule.
2. The one mechanical rule is per function, and off by default
Clippy's too_many_lines is the only size lint in the compiler toolchain.
- Default threshold,
clippy_config/src/conf.rs:too_many_lines_threshold("too-many-lines-threshold"): u64 = 100, documented as "The maximum number of lines a function or method can have". - Group,
clippy_lints/src/functions/mod.rs:pub TOO_MANY_LINES, pedantic, "functions with too many lines". - Scope,
clippy_lints/src/functions/too_many_lines.rs: it measures the function body span, skips closures ("Closures must be contained in a parent body, which will be checked"), and counts only lines containing code outside comments.
Because the group is pedantic (allow-by-default), and DropTerm's just clippy is cargo clippy --all-targets ... -- -D warnings over default and
warn lints only, the lint has never fired here. There is no too_many_lines for
files, and no rustfmt option that limits total file lines — Configurations.md
exposes only per-line widths such as max_width.
3. The module lints control layout, not size
Clippy's module_style.rs declares MOD_MODULE_FILES and
SELF_NAMED_MODULE_FILES, both restriction:
"Checks that module layout does not use inline modules. Inline test modules (anything annotated with
#[cfg(test)]) are not linted."
So the one lint that could push code out of a file explicitly exempts test modules. Nothing in the lint set caps a file's length.
4. Tests are supposed to be inline, which is where the bytes are
The Book, "Test Organization"
"You'll put unit tests in the src directory in each file with the code that they're testing. The convention is to create a module named tests in each file to contain the test functions and to annotate the module with cfg(test)."
That convention is enforced in the same direction by
clippy::tests_outside_test_module (added 1.70.0, restriction): test
functions must be inside a testing module, and items_after_test_module keeps
that module last. Both push tests into the source file and neither limits its
size. A file-heavy codebase is the straightforward outcome of following the
Book.
5. The books with a reputation for authority say nothing
- Effective Rust (David Drysdale) lists 35 items across types, traits, concepts, dependencies, tooling, and beyond-standard-Rust. None addresses module size, file size, or splitting source files. Closest: Item 22 "Minimize visibility" and Item 25 "Manage your dependency graph" — neither is about file sizing.
- Rust Design Patterns (
rust-unofficial/patterns): the landing page and the idioms index give no size guidance; the nearest statement is "Keep It Simple, Stupid" about unnecessary complexity.
What DropTerm has today
Measured 2026-12-06 over dropterm/ (109 .rs files, 200,691 lines; carried/
excluded as vendored):
- 48 files are ≥1,000 lines — 44% of the crate.
- 22 files are ≥2,000 lines; eight ≥5,000; two ≥10,000.
app_shell.rsis 37,799 lines: 12,464 production, 25,335 inline tests.- 49 functions exceed clippy's 100-code-line threshold; the worst are
lua_host.rs:2414 install_port(656),engine.rs:4087 update(425), andterminal/view.rs:2602 paint_pane(324). - No
[lints]table in DropTerm's own manifests (the only one in the tree is vendoredcarried/gpui-component/Cargo.toml), and noclippy.toml, so the only mechanical size rule in Rust is switched off for this crate.
Scoring
Four dimensions, each graded on the same A–F ladder, and a file takes the worst grade among them. Thresholds are stated here so the score can be recomputed; two are project rules, one is the official clippy rule.
| Dimension | A | B | C | D | F | Authority |
|---|---|---|---|---|---|---|
| Total lines | <1,000 | 1–2k | 2–5k | 5–10k | ≥10k | internal review signal (code-review-and-quality) |
Inline mod tests lines | ≤500 | 501–2k | 2–5k | 5–10k | ≥10k | project rule (AGENTS.md) |
| Longest function, code lines | ≤100 | 101–199 | 200–299 | 300–499 | ≥500 | clippy::too_many_lines (primary) |
| File | Total | Prod | Test | Longest fn | Grade | Deciding dimension |
|---|---|---|---|---|---|---|
src/app_shell.rs | 37,799 | 12,464 | 25,335 | 293 | F | total + inline tests |
src/core/lua_host.rs | 17,144 | 5,500 | 11,644 | 656 | F | total + function |
src/panels.rs | 7,211 | 989 | 6,222 | 112 | D | inline tests |
src/core/terminal/engine.rs | 6,079 | 6,079 | 0 | 425 | D | total + function |
src/core/terminal/suggest/tests.rs | 5,873 | 0 | 5,873 | 130 | D | total |
src/core/plugins_manifest.rs | 5,700 | 1,964 | 3,736 | 181 | D | total |
src/core/settings/tests.rs | 5,353 | 0 | 5,353 | 102 | D | total |
src/settings.rs | 5,052 | 4,437 | 615 | 129 | D | total |
src/terminal/view/tests.rs | 4,922 | 0 | 4,922 | 218 | C | function |
src/core/slots.rs | 4,560 | 1,243 | 3,317 | 122 | C | total |
src/terminal/view.rs | 3,984 | 3,984 | 0 | 324 | D | function |
src/core/settings.rs | 3,867 | 3,867 | 0 | 109 | C | total |
src/tab_bar.rs | 2,518 | 2,518 | 0 | 211 | C | function |
src/core/terminal/engine/tests.rs | 7,456 | 0 | 7,456 | 77 | D | total |
src/core/terminal/suggest.rs | 3,180 | 3,180 | 0 | 71 | C | total |
src/core/plugins_install.rs | 2,871 | 1,271 | 1,600 | 74 | C | total |
src/tab_bar/tests.rs | 2,849 | 0 | 2,849 | 85 | C | total |
src/core/config/tests.rs | 2,674 | 0 | 2,674 | 77 | C | total |
src/band.rs | 2,176 | 1,140 | 1,036 | 97 | C | total |
src/main.rs | 2,073 | 716 | 1,357 | 88 | C | total |
src/executor/layer_shell.rs | 2,058 | 937 | 1,121 | 63 | C | total |
src/terminal/suggest.rs | 2,011 | 866 | 1,145 | 100 | C | total |
Distribution: 2 F, 7 D, 13 C, none A or B. Every graded file fails the project's 1,000-line signal and most fail the 500-line test-module rule; 49 functions fail the only official rule. The score is not "how close to a Rust standard" — no such standard exists — it is "how far past the two project signals, with the official function limit as the one hard line".
Recommendation
There is nothing upstream to lean on, so the guard has to be ours and mechanical, because the current gate is all-green or all-red and neither state ever mentions size.
- Turn on the one official rule. Add
too_many_lines = "warn"to[lints.clippy](default 100, or raise the threshold inclippy.tomlto 200 as a first ratchet). Today the repo has no lints table, so the rustc/clippy gate cannot see function size at all. This is a decision for the owner because it will surface 49 findings at once. - Make the 500-line test rule a check, not a paragraph. It currently lives
only in
AGENTS.mdand is violated in 11 files. A recipe comparing an inlinemod testslength against 500 fails loudly and cannot go stale. - Ratchet the file list. Add a checked-in allowlist of the 48 files ≥1,000
lines with their current sizes; fail when a listed file grows and when a new
file crosses 1,000. That is the only shape that makes a size rule survive
an all-green commit stream, because the alternative (
too_many_lineson functions only) never looks at whole files.
Rejected alternatives
- Lean on the review skill's 1,000-line file signal. That is the current
state and it failed: the signal is advisory, it is only read by
/reviewand/ship, and the commits that grewapp_shell.rsfrom 4,400 to 37,799 lines were small fixes that never ran either. - Enable the whole
pedanticgroup. It would surface the 49 size findings plus every other pedantic lint, burying the size signal in unrelated noise. - Split files to a numeric target. No primary source supports a target
size, and splitting
app_shell.rsby line count would produce arbitrary modules; the real work is naming boundaries, which is design, not a lint fix.
Sources
- The Book — Test Organization — unit tests inline under
#[cfg(test)] mod tests; integration tests intests/. Fetched 2026-12-06. - clippy
too_many_linesimplementation — body-span counting, closures skipped. Fetched 2026-12-06. - clippy lint declaration + group —
TOO_MANY_LINES, pedantic, "functions with too many lines". Fetched 2026-12-06. - clippy configuration defaults —
too_many_lines_threshold = 100. Fetched 2026-12-06. - clippy
module_style—MOD_MODULE_FILES/SELF_NAMED_MODULE_FILES,restriction, inline test modules exempt. Fetched 2026-12-06. - clippy
tests_outside_test_module— tests must be inside a testing module; 1.70.0;restriction. Fetched 2026-12-06. - Rust Style Guide source — nine chapters, no file-size guidance. Fetched 2026-12-06.
- Rust API Guidelines checklist — no file/module size guideline. Fetched 2026-12-06.
- rustfmt
Configurations.md— per-line widths only; no file-length option. Fetched 2026-12-06. - Effective Rust — 35 items, none on file size. Fetched 2026-12-06.
- Rust Design Patterns and its idioms index — no size guidance. Fetched 2026-12-06.
Unverified
- The "around 1,000 lines per file" figure has no primary source. It appears
only as an internal heuristic in this repo's
code-review-and-qualityskill; no Rust-language or tooling document endorses it. rustfmtwas checked by its option headings, not by an exhaustive semantic audit of every option; the conclusion "no file-size option" is from that listing.- Rust for Rustaceans was not surveyed: it has no public primary text to quote, and secondary summaries were deliberately excluded.
- The pattern book was checked at its landing page and idioms index only; a size recommendation buried in a single pattern page is not ruled out.