Skip to content

S0001 crate-lines

Rule: A crate's src/ stays under its line limit.

Code S0001 (stable, never reused)
Id crate-lines
Category size
Source spirit_level
Fix by hand

Level per tier

Tier Level Reason
small off
small-workspace off
medium warn split a crate before it passes ~20,000 lines: one crate is one serial compile step
big warn split a crate before it passes ~20,000 lines: one crate is one serial compile step
ai off
embedded off
ui off
egui off
units-strict off
units-paranoid off

Parameters

Name Type Default Meaning
max-lines integer 20000 code lines in src/ above which a crate is reported

Why

rustc's front end runs one crate on one thread, so a big crate is one long serial step of every build, and every change in it rebuilds all of it. Past about 20,000 lines a crate also stops having one subject: tpm_cli's root crate reached 316,000 lines with 85% of them in one tangle. Split before it grows on.

Code lines are lines that are not blank and not only a comment, in src/ (tests apart, see test-lines). Crates the crate map marks generated are not counted.

Exceptions with expiry

A crate that must stay big for a while gets a limit of its own, a reason and an expiry, so every exception is visible and temporary:

[[exceptions]]
lint = "crate-lines"
crates = ["foo_editor"]
max-lines = 45000
level = "deny"
reason = "split into foo_editor_core and foo_editor_ui is FEATURES SPLIT-3"
expires = "2027-03-31"

spl config lists every exception with its reason and expiry.

How to fix

Split along the seams: types into a _core crate, a heavy dependency into a crate of its own, parts that change at their own pace apart.

Configure

[lints.crate-lines]
level = "deny"
max-lines = 20000
reason = "why this project wants it at this level"

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