cargo clippy: Usage, Options & Common CI Errors
Lint Rust for correctness, style, and performance.
cargo clippy is an official lint tool that catches common mistakes and non-idiomatic code. In CI you typically promote warnings to errors so a lint regression fails the build.
What it does
Runs the compiler with Clippy lint passes enabled, emitting suggestions across correctness, style, complexity, and performance categories. Lint levels are controlled with -W, -A, and -D after a -- separator.
Common usage
cargo clippy # lint the package
cargo clippy --workspace --all-targets # lint everything
cargo clippy --fix # auto-apply fixes
cargo clippy -- -D warnings # fail on any warning
cargo clippy -- -A clippy::too_many_arguments # allow one lintCommon CI error: clippy component missing
On a minimal toolchain CI fails with "error: no such command: clippy" or "error: the clippy component is not installed." Fix: install it with rustup component add clippy (the dtolnay/rust-toolchain action accepts components: clippy).
Options
| Flag | Effect |
|---|---|
| --fix | Apply machine-applicable fixes |
| --all-targets | Lint tests and examples too |
| -- -D warnings | Treat warnings as errors |
| -- -W clippy::pedantic | Enable the pedantic group |