Skip to content
Latchkey

Cargo clippy "-D warnings" failures in CI

CI runs clippy with -D warnings, which promotes every lint to an error. A clippy suggestion that is a harmless warning locally fails the pipeline, so the build stops on lints your local cargo build ignores.

What this error means

The clippy step fails with one or more error: ... lines (each ending in #[deny(clippy::...)] on by default) plus error: aborting due to N previous errors. It is deterministic for the source and clippy version.

cargo
error: this `.clone()` on a Copy type is redundant
  --> src/calc.rs:8:13
   |
8  |     let y = x.clone();
   |             ^^^^^^^^^ help: try removing the `.clone()`: `x`
   |
   = note: `-D clippy::clone-on-copy` implied by `-D warnings`

Diagnose it: toolchain, features, or a stale target dir?

Cargo failures that only appear in CI are usually a different toolchain channel, a different feature set resolved by the dependency graph, or a target directory restored from a cache built with different flags.

Terminal
rustc --version --verbose
cargo --version
cat rust-toolchain.toml 2>/dev/null

# which features actually got enabled across the graph?
cargo tree -e features | head -40

# rule out a poisoned cache before anything else
cargo clean && cargo build --locked

Common causes

Warnings promoted to errors

The CI invocation passes -- -D warnings, so any clippy lint -- even a style nit -- becomes a build-failing error.

New lints from a clippy upgrade

A newer toolchain ships new lints that fire on existing code, breaking a previously green build.

How to fix it

Fix the lints clippy reports

Apply the suggestions; many are auto-fixable.

Terminal
cargo clippy --fix --allow-dirty --workspace
cargo clippy --workspace --all-targets -- -D warnings

Allow a specific lint deliberately

When a lint is a false positive, allow it narrowly rather than dropping -D warnings.

src/calc.rs
#[allow(clippy::clone_on_copy)] // justified: trait-object boundary
let y = x.clone();

How to prevent it

  • Run cargo clippy -- -D warnings locally before pushing.
  • Pin the clippy toolchain so a CI upgrade does not surprise you with new lints.
  • Allow individual lints with justification instead of disabling the gate.

Frequently asked questions

What causes Cargo clippy "-D warnings" failures in CI?
There are 2 common causes: warnings promoted to errors and new lints from a clippy upgrade. The CI invocation passes -- -D warnings, so any clippy lint -- even a style nit -- becomes a build-failing error.
How do I fix Cargo clippy "-D warnings" failures in CI?
There are 2 fixes depending on which cause you have: fix the lints clippy reports and allow a specific lint deliberately. Work through them in order, since the first is the most common.
What does Cargo clippy "-D warnings" failures in CI actually mean?
The clippy step fails with one or more error: ...
How do I stop Cargo clippy "-D warnings" failures in CI happening again?
Run cargo clippy -- -D warnings locally before pushing. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card