cargo clippy --all-targets: Lint Gate in CI
cargo clippy runs the Clippy lint suite; --all-targets lints tests, benches, and examples too, and -- -D warnings makes any lint fail the build.
Plain clippy only checks the default targets and exits 0 on warnings. The CI form lints everything and denies warnings so lint regressions cannot merge.
What it does
cargo clippy compiles the crate with the Clippy lint driver and reports lints. --all-targets includes tests, examples, and benches; arguments after -- are passed to rustc/clippy, so -D warnings promotes all warnings to errors.
Common usage
cargo clippy --all-targets --all-features --locked -- -D warnings
cargo clippy -p mycrate -- -D clippy::all
cargo clippy --fix --allow-dirty # auto-apply suggestionsFlags
| Flag | What it does |
|---|---|
| --all-targets | Lint lib, bins, tests, benches, and examples |
| --all-features | Lint with all features enabled |
| -- -D warnings | Deny all warnings (turns them into errors) |
| -- -W clippy::pedantic | Enable the pedantic lint group |
| --fix | Apply machine-applicable suggestions |
| --no-deps | Do not lint dependencies |
In CI
Clippy is a separate component; install it with rustup component add clippy. It reuses the same target/ directory as a normal build, so cache target/ and ~/.cargo to avoid recompiling. Note clippy and cargo build can invalidate each other's cache when run with different flags.
Common errors in CI
"error: could not find clippy in ..." means the component is not installed; add rustup component add clippy. "error: this lint expectation is unfulfilled" or any lint message followed by "error: could not compile ... due to N previous errors" is -D warnings doing its job. "error: failed to run rustc to learn about target-specific information" usually means a missing target.