rgoussu@goussu: ~/library/rust/toolchain
~/library/rust/toolchain cat clippy.md

clippy — the lint collection

# Rust's official linter — 750+ lints in leveled categories from correctness to pedantic, cargo clippy --fix, clippy.toml, and sane CI policy.

Conceptsaved 2026-08-09 #rust#tooling#lint#quality

Overview

Clippy is the official lint suite, a rustup component run as cargo clippy, with over 750 lints that go far beyond the compiler's built-in warnings: idiom upgrades, API misuse, performance smells, outright bugs. Because it plugs into rustc's own lint-level machinery (allow/warn/deny attributes), policy is expressed in source, per item or per crate, rather than in an external config — closer to a compiler feature than to the JVM's checkstyle/SpotBugs layer, and roughly covering what staticcheck does for Go.

Key points

  • Categories with default levels: correctness (deny — these are bugs), suspicious and style and complexity and perf (warn), pedantic and nursery and restriction and cargo (allow — opt-in only).
  • Turning on pedantic wholesale is a trap: #![warn(clippy::pedantic)] plus targeted #[allow]s works for greenfield libraries; on applications, cherry-picking individual pedantic lints ages better.
  • cargo clippy --fix applies machine-applicable suggestions — safe, and an excellent idiom tutor when upgrading old code or learning the language.
  • CI gate: cargo clippy --all-targets --all-features -- -D warnings — lint tests and examples too, deny drift. Prefer failing on warnings in CI over deny attributes in source (deny breaks builds for downstream users on newer clippy versions with new lints).
  • clippy.toml configures individual lints' thresholds (too-many-arguments, cognitive-complexity, MSRV for idiom suggestions) — not lint selection, which stays in source or on the command line.
  • #[allow(clippy::lint_name, reason = "…")]: scoped, documented exemptions at the narrowest item that needs them — the review-friendly form.
  • New lints arrive every six weeks with the toolchain; a version bump can introduce warnings. That's the deal — treat the diff as a free code review.

Examples

cargo clippy --all-targets -- -D warnings     # the CI invocation
cargo clippy --fix                            # apply machine-applicable suggestions
#![warn(clippy::pedantic)]                    // library crate root
#[allow(clippy::module_name_repetitions, reason = "re-exported at crate root")]
pub struct ConfigError { /* … */ }

Related