cargo clippy "-D warnings" fails the build in CI
CI commonly runs cargo clippy -- -D warnings, which turns every clippy lint into a hard error. Any lint then makes the crate fail to compile, and cargo exits 101.
What this error means
clippy prints "error: ..." for what would be warnings, each with a "#[deny(clippy::X)] on by default" note, and ends with "error: could not compile crate due to N previous errors".
error: this expression creates a reference which is immediately dereferenced by the compiler
--> src/main.rs:7:14
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: could not compile `app` (bin "app") due to 1 previous errorCommon causes
Warnings are denied, so lints are errors
-D warnings (or RUSTFLAGS=-Dwarnings) promotes every clippy and rustc warning to an error, so even minor lints fail the build.
New lints from a newer clippy/toolchain
A toolchain bump ships new or stricter clippy lints that now fire on existing code under the deny gate.
How to fix it
Fix the lints (autofix where possible)
- Run
cargo clippy --fixto apply machine-applicable suggestions. - Address the remaining lints by hand using each suggestion.
- Re-run with
-D warningsto confirm a clean compile.
cargo clippy --fix --allow-dirty
cargo clippy -- -D warningsAllow a specific lint deliberately
If a lint is a false positive, allow just that lint with an attribute rather than dropping -D warnings.
#[allow(clippy::needless_borrow)]
fn f() { /* ... */ }How to prevent it
- Run
cargo clippy -- -D warningslocally before pushing. - Pin the Rust toolchain so new lints arrive on purpose.
- Scope
#[allow(...)]narrowly instead of disabling the gate.