Skip to content
Latchkey

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

Terminal
cargo clippy --all-targets --all-features --locked -- -D warnings
cargo clippy -p mycrate -- -D clippy::all
cargo clippy --fix --allow-dirty            # auto-apply suggestions

Flags

FlagWhat it does
--all-targetsLint lib, bins, tests, benches, and examples
--all-featuresLint with all features enabled
-- -D warningsDeny all warnings (turns them into errors)
-- -W clippy::pedanticEnable the pedantic lint group
--fixApply machine-applicable suggestions
--no-depsDo 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →