Skip to content

Rust and Cargo policies

These policies check Cargo.toml manifests, Cargo workspaces, and Rust source files. Unless noted, a manifest policy checks every Cargo.toml in the repository. Policies marked root only check only the Cargo.toml at the repository root.

repopo.config.ts
import { makePolicy, type RepopoConfig } from "repopo";
import { CargoTomlRequired, CargoTomlSorted } from "repopo/policies";
export default {
policies: [
makePolicy(CargoTomlRequired, { config: { minimumEdition: "2021" } }),
makePolicy(CargoTomlSorted),
],
} satisfies RepopoConfig;

Checks that fields exist in the [package] section of Cargo.toml.

OptionTypeDefaultDescription
requiredstring[]["license", "description"]Fields that must exist.
minimumEditionstringLowest allowed edition, such as "2021".
requireRustVersionbooleanfalseRequire rust-version (MSRV).
expectedValuesRecord<string, string>Fields that must have these exact values.

Auto-fixable: No.

Checks the license field against the SPDX license list.

OptionTypeDefaultDescription
allowedLicencesstring[]Only these SPDX identifiers are accepted.
validateSpdxbooleantrueValidate against SPDX with spdx-correct.
skipWorkspacebooleantrueSkip workspace-only manifests that have no [package] section.

SPDX validation needs the optional peer dependency spdx-correct.

Auto-fixable: Yes. --fix replaces a correctable identifier, such as MIIT or mit, with the canonical one (MIT).

Checks that Cargo.toml has a [lints.clippy] section and, optionally, minimum lint levels.

makePolicy(CargoLintsConfigured, { config: { required: { pedantic: "warn", nursery: "warn" } } });
OptionTypeDefaultDescription
requireSectionbooleantrueRequire a [lints.clippy] section.
requiredRecord<string, string>Lint names (without clippy::) mapped to a minimum level, "warn" or "deny".

Auto-fixable: No.

Checks that the missing_docs lint is set to "warn" or "deny" in the [lints.rust] section of Cargo.toml.

OptionTypeDefaultDescription
checkCargoLintsbooleantrueCheck [lints.rust] for missing_docs.

Auto-fixable: No.

Checks that the keys in Cargo.toml dependency sections are in alphabetical order.

OptionTypeDefaultDescription
sectionsstring[]["dependencies", "dev-dependencies", "build-dependencies"]Sections to check.

Auto-fixable: Yes. --fix sorts the sections line by line, so formatting and comments are kept.

Reports dependency versions that are wildcards or too loose.

OptionTypeDefaultDescription
denystring[]["*"]Version prefixes that fail the check.
warnstring[][">="]Version prefixes that produce a warning.
allowDevbooleantrueApply only deny rules, not warn rules, to dev-dependencies.

Checks dependencies, build-dependencies, and dev-dependencies.

Auto-fixable: No.

Checks whether Cargo.lock is committed, based on the crate type. Binary crates should commit the lockfile. Library crates usually don’t.

OptionTypeDefaultDescription
binaries"require" | "warn" | "ignore""require"Rule for binary crates when Cargo.lock is missing.
libraries"require" | "warn" | "ignore""ignore"Rule for library crates. "warn" reports a committed Cargo.lock.

Auto-fixable: No.

Root only. Checks that every path in [workspace].members exists. Simple globs such as crates/* are expanded.

OptionTypeDefaultDescription
validatePathsbooleantrueCheck that member paths exist on disk.

Auto-fixable: No.

Root only. Checks that workspace members inherit shared fields from [workspace.package], for example with version.workspace = true.

OptionTypeDefaultDescription
inheritstring[]["version", "authors", "license", "repository"]Fields members must inherit.
allowOverridesstring[]Member paths that may set their own values. A trailing * matches a prefix.

Auto-fixable: No.

Repository policy. Compares dependency versions across the members of the root Cargo workspace and reports mismatches. Runs once per check, even with --stdin, when the root Cargo.toml is in its inventory.

OptionTypeDefaultDescription
detectMismatchesbooleantrueReport a dependency that has different versions in different members.
requireWorkspaceDepsstring[]Dependencies that must be declared in [workspace.dependencies].

Auto-fixable: No.

Root only. Requires a toolchain file so every build uses the same Rust version.

OptionTypeDefaultDescription
acceptedNamesstring[]["rust-toolchain.toml", "rust-toolchain"]Accepted file names.

Auto-fixable: No.

Root only. Requires a rustfmt configuration file.

OptionTypeDefaultDescription
acceptedNamesstring[]["rustfmt.toml", ".rustfmt.toml"]Accepted file names.

Auto-fixable: No.

Checks that documentation files exist next to each Cargo.toml.

OptionTypeDefaultDescription
requiredstring[]["README.md"]Files that must exist.
recommendedstring[]Files that produce a warning when missing.

Auto-fixable: No.

Requires a safety comment within the five lines before each unsafe block, unsafe fn, or unsafe impl in .rs files.

OptionTypeDefaultDescription
requireCommentstring"// SAFETY:"Comment prefix to look for.
excludePathsstring[]Skip files whose path contains any of these strings, such as FFI modules.

Auto-fixable: No.

Reports committed Rust build artifacts: files ending in .rlib, .rmeta, .d, .so, .dylib, .dll, .exe, or .pdb. Paths containing test/ or fixture are allowed.

Auto-fixable: No. Remove the files from Git and add /target/ to .gitignore.