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`

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 ""clippy: -D warnings""?
The CI invocation passes -- -D warnings, so any clippy lint -- even a style nit -- becomes a build-failing error.
How do I fix "clippy: -D warnings"?
Apply the suggestions; many are auto-fixable.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card