M0023 workspace-inheritance¶
Rule: Members inherit the shared package keys from [workspace.package].
| Code | M0023 (stable, never reused) |
| Id | workspace-inheritance |
| Category | workspace |
| Source | spirit_level |
| Fix | exact: spl check --fix applies it |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | deny |
edition, rust-version, licence and repository are declared once in [workspace.package] |
| medium | deny |
edition, rust-version, licence and repository are declared once in [workspace.package] |
| big | deny |
edition, rust-version, licence and repository are declared once in [workspace.package] |
| ai | off | |
| embedded | off | |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
keys |
list of strings | ["edition", "rust-version", "license", "repository"] |
the keys every member inherits |
Why¶
Edition, rust-version, licence and repository are the same for every crate of a workspace. Declared once in [workspace.package] and inherited, they cannot drift apart, and a change is one line.
Example¶
# root Cargo.toml
[workspace.package]
edition = "2024"
rust-version = "1.88"
license = "MIT OR Apache-2.0"
# crates/foo/Cargo.toml
[package]
name = "foo"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
How to fix¶
spl check --fix rewrites key = "..." into key.workspace = true, or adds the line after name when the key is missing. A key missing from [workspace.package] itself is added by hand. The keys checked are the parameter keys.
Configure¶
[lints.workspace-inheritance]
level = "deny"
keys = ["edition", "rust-version", "license", "repository"]
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(workspace-inheritance) <reason> (waivers); the code works there too, as in [lints.M0023].