Clippy
Clippy is Rust's linter for correctness, performance, and idiomatic code. Run it on every PR with -D warnings to treat lints as errors.
Busca en todas las páginas de la documentación
Clippy is Rust's linter for correctness, performance, and idiomatic code. Run it on every PR with -D warnings to treat lints as errors.
cargo clippy --workspace --all-targets -- -D warnings[lints.clippy]
enum_glob_use = "deny"When to reach for this: Always in CI; locally before pushing Rust changes.
# Local
cargo clippy --all-targets -- -W clippy::pedantic
# CI (strict)
cargo clippy --workspace --all-targets --all-features -- -D warnings// clippy catches:
let v = vec![1, 2, 3];
let x = v.iter().cloned().collect::<Vec<_>>(); // use .copied() for Copy typesWhat this demonstrates:
--all-targets includes tests and benches-D warnings promotes warnings to errors[lints.clippy] sets default levels (Rust 1.74+)| Group | Examples |
|---|---|
| correctness | almost certainly bugs |
| suspicious | likely mistakes |
| style | idiomatic Rust |
| perf | unnecessary alloc/clone |
| pedantic | noisy but educational |
#[allow(clippy::too_many_arguments)]
fn legacy_api(...) { }
// prefer with reason:
#[allow(clippy::cast_possible_truncation)] // protocol defines u8 wire format#![allow(...)] at crate root sparinglyallow--all-targets.cargo clippy --all-features job.allow with comment.clippy::redundant_clone seriously in hot paths.| Alternative | Use When | Don't Use When |
|---|---|---|
rustc lints only | Minimal setup | Missing high-value clippy checks |
cargo-deny | Licenses/advisories | Replacing clippy style/correctness |
| Manual review | Never alone | Complement to clippy |
Clippy is additional passes; both run via cargo clippy.
You cannot fix dep code; -A clippy::lint_name at crate root only for unfixable third-party macro expansions.
Usually no for large codebases; enable for new crates or incremental ratchet.
Run clippy on MSRV toolchain in CI matrix to catch unsupported APIs.
Some lints support cargo clippy --fix --allow-dirty - review diff carefully.
Single command at root with --workspace shares target dir cache.
--all-targets includes build scripts; fix or allow explicitly.
Refactor to builder struct or config struct; allow only for generated/FFI bindings.
Cached target/ helps; run after fmt; parallel with tests if runners allow.
Prefer [lints.clippy] in Cargo.toml for crate-wide policy; line allows for exceptions.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026