Configuring Clippy
clippy.toml (and Cargo.toml [lints.clippy]) tune thresholds, disallowed methods, and third-party macros so Clippy matches your team's standards.
Busca en todas las páginas de la documentación
clippy.toml (and Cargo.toml [lints.clippy]) tune thresholds, disallowed methods, and third-party macros so Clippy matches your team's standards.
# clippy.toml
cognitive-complexity-threshold = 25
disallowed-methods = [
{ path = "std::env::var", reason = "use config crate" },
]When to reach for this: Banning unwrap in apps, raising complexity limits, or documenting disallowed APIs.
# clippy.toml at workspace root
avoid-breaking-exported-api = false
too-many-lines-threshold = 120
disallowed-types = [
{ path = "std::sync::Mutex", reason = "use parking_lot::Mutex or tokio::sync::Mutex" },
]# crates/api/Cargo.toml
[lints.clippy]
unwrap_used = "deny"
expect_used = "deny"cargo clippy --workspace -- -D warningsWhat this demonstrates:
clippy.toml applies to all members[lints.clippy] for stricter bins vs libsdisallowed-methods fails compile with custom reason| Key | Purpose |
|---|---|
cognitive-complexity-threshold | Function complexity cap |
too-many-arguments-threshold | Arity warning level |
disallowed-names | Ban variable names like foo |
msrv | Avoid lints requiring newer Rust than MSRV |
third-party = { yaml = true }serde, tracing macroscfg(test).msrv = "1.97.0" in clippy.toml.clippy.toml in member crate.| Alternative | Use When | Don't Use When |
|---|---|---|
Only [lints.clippy] | Simple allow/deny | Need disallowed-methods list |
#[allow] only | One-off exceptions | Org-wide banned APIs |
| Custom rustc lint crate | Extreme policies | Standard app teams |
Same discovery: package dir, then ancestors to workspace root.
unwrap_used = "deny" in app crate manifests; allow in #[cfg(test)] modules.
Array of { path = "...", reason = "..." } entries.
It filters suggestions; still set rust-version in Cargo.toml for cargo enforcement.
Axum handlers may be longer; raise threshold or extract helpers instead of blanket allow.
Same config; relax specific lints inside mod tests with inner allows.
Strict clippy.toml at root; per-crate [lints] relax for legacy crate during migration.
Introduce intentional violation; confirm clippy fails with expected lint name.
Enable in clippy.toml to reduce macro expansion noise.
Review release notes when bumping Rust; new lints may need threshold tweaks.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026