TL;DR: Clippy is Rust's official lint tool, installed with
rustupand run withcargo clippy. It provides 700+ lints across correctness, performance, style, and idiomatic Rust patterns; catching issues the compiler misses. Every Rust project should run Clippy in CI. Configure lints with#[allow(clippy::lint_name)]per-item or inCargo.toml. Runningcargo clippy --fixauto-applies safe suggestions.
What Is Clippy?
Clippy is the official Rust linter; a collection of 700+ rules that catch bugs, suggest idiomatic patterns, and flag performance issues beyond what rustc alone reports.
cargo clippy # run lints on current package
cargo clippy --all-targets # include tests, benches, examples
cargo clippy -- -D warnings # treat warnings as errors (for CI)
cargo clippy --fix # auto-apply safe suggestionsExample Clippy catch:
// Clippy: "using `x.len() == 0` is inefficient; use is_empty()"
if my_vec.len() == 0 {
println!("empty");
}
// Clippy's suggestion:
if my_vec.is_empty() {
println!("empty");
}What Categories of Lints Does Clippy Have?
Clippy organizes lints into groups; you can enable or deny entire groups.
| Group | What it catches |
|---|---|
clippy::correctness | Outright bugs (enabled by default, deny-level) |
clippy::suspicious | Probably-wrong code |
clippy::style | Non-idiomatic Rust patterns |
clippy::complexity | Unnecessarily complex code |
clippy::perf | Performance improvements |
clippy::pedantic | Stricter style (not on by default) |
clippy::nursery | Experimental lints |
clippy::restriction | Opinionated, project-specific rules |
# Enable pedantic lints for stricter checking
cargo clippy -- -W clippy::pedanticHow Do You Suppress a Clippy Warning?
Use #[allow(clippy::lint_name)] to silence a specific lint for an item, or add it to Cargo.toml for the whole crate.
// Silence for one function
#[allow(clippy::too_many_arguments)]
fn configure(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32) {}
// Silence for one expression
let result = #[allow(clippy::cast_precision_loss)] (large_int as f64);In Cargo.toml (crate-wide):
[lints.clippy]
too_many_arguments = "allow"
pedantic = "warn"Always prefer fixing the issue over silencing; use #[allow] only when the lint is genuinely wrong for your use case.
How Do You Run Clippy in CI?
Use -D warnings to make Clippy fail the build on any warning; standard practice for Rust CI pipelines.
# GitHub Actions example
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warningsOr deny specific groups in code:
// In lib.rs or main.rs
#![deny(clippy::correctness)]
#![warn(clippy::perf, clippy::style)]What Are Some Common Clippy Suggestions?
// ❌ → ✅ Use is_empty() instead of len() == 0
if v.len() == 0 → if v.is_empty()
// ❌ → ✅ Use ? instead of unwrap() in fallible functions
let x = some_result.unwrap(); → let x = some_result?;
// ❌ → ✅ Simplify clone on copy types
let x = y.clone(); → let x = y; // if y: Copy
// ❌ → ✅ Use if-let instead of match with single arm
match opt { Some(v) => use(v), None => {} } → if let Some(v) = opt { use(v) }
// ❌ → ✅ Use .map() instead of manual match on Option
match opt { Some(v) => Some(v + 1), None => None } → opt.map(|v| v + 1)
// ❌ → ✅ Avoid needless borrow
fn takes_str(s: &str) {}
takes_str(&String::from("hi")) → takes_str("hi")Frequently Asked Questions
Yes; rustup installs Clippy automatically. Check with cargo clippy --version. If missing: rustup component add clippy.
Clippy runs the compiler internally, so it takes about the same time as a regular cargo check. Incremental compilation applies; only changed files are re-linted.
For new projects, yes; it enforces stricter idioms early. For existing codebases, enabling it can be noisy. Add #[allow(clippy::pedantic)] at the crate level first, then fix lints one at a time.
cargo clippy --fix applies machine-applicable suggestions automatically. Not all lints are auto-fixable; Clippy marks which ones are safe to auto-apply. Review the diff before committing.
rustfmt formats code (whitespace, line breaks, indentation). Clippy lints code (logic, idioms, correctness). They are complementary; use both.
Sources
- Clippy GitHub; rust-lang/rust-clippy
- Clippy Lints List: All 700+ lints with examples
Related Glossary Terms
- Cargo: Clippy is invoked through
cargo clippy - Rustup: Clippy is installed and managed through the Rust toolchain
- Macro: Many Clippy lints target macro usage patterns
- Criterion: Clippy helps catch wasteful code paths before you benchmark them with Criterion
- macro-rules: Clippy includes lints for common declarative macro patterns and pitfalls
- Panic: Clippy warns about panic-prone patterns like unnecessary
unwrap()use
Keep Reading
- Learn Rust in 2026: Clippy is part of every serious Rust setup
- Best Way to Learn Rust in 2026: using linting tools to learn idiomatic Rust
- Rust 2024 Edition: What's New: new Clippy lints in the 2024 edition
