A collection of lints to catch common mistakes and improve Rust code
Clippy is Rust’s official linter that provides over 800 lints to catch common mistakes and improve code quality. It helps enforce best practices and idiomatic Rust code.
Clippy is a powerful static analysis tool that goes beyond the compiler’s built-in warnings. It analyzes your code for potential bugs, performance issues, and style violations.
Clippy contains over 800 lints organized into categories based on severity and purpose. See the complete lint list.
Clippy organizes lints into the following categories:
Category
Description
Default Level
clippy::correctness
Code that is outright wrong or useless
deny
clippy::suspicious
Code that is most likely wrong or useless
warn
clippy::style
Code that should be written in a more idiomatic way
warn
clippy::complexity
Code that does something simple but in a complex way
warn
clippy::perf
Code that can be written to run faster
warn
clippy::pedantic
Lints which are rather strict or have occasional false positives
allow
clippy::restriction
Lints which prevent the use of language and library features
allow
clippy::nursery
New lints that are still under development
allow
clippy::cargo
Lints for the cargo manifest
allow
The restriction category should not be enabled as a whole. These lints may contradict each other and other categories. Enable them individually based on your specific needs.
# Run clippy on the current cratecargo clippy# Automatically apply suggestionscargo clippy --fix# Run on all targets (bins, tests, examples)cargo clippy --all-targets# Run with all features enabledcargo clippy --all-features
# Run on a specific package in a workspacecargo clippy -p example# Run only on the specified package, excluding dependenciescargo clippy -p example -- --no-deps
// Allow a specific lint for the entire crate#![allow(clippy::single_match)]// Warn on a lint#![warn(clippy::pedantic)]// Deny a lint (makes it an error)#![deny(clippy::unwrap_used)]// Allow for a specific function#[allow(clippy::too_many_arguments)]fn complex_function(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32) { // ...}
# Allow a specific lintcargo clippy -- -A clippy::lint_name# Warn on a specific lintcargo clippy -- -W clippy::lint_name# Deny all warningscargo clippy -- -D warnings# Enable pedantic lintscargo clippy -- -W clippy::pedantic
// ❌ Bad: Incorrect use of clonelet x = Box::new(5);let y = x.clone(); // Use *x instead// ❌ Bad: Suspicious else formattingif condition { do_something();}else { // Should be on same line as closing brace do_other();}