Skip to main content
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.

Overview

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.

Lint Categories

Clippy organizes lints into the following categories:
CategoryDescriptionDefault Level
clippy::correctnessCode that is outright wrong or uselessdeny
clippy::suspiciousCode that is most likely wrong or uselesswarn
clippy::styleCode that should be written in a more idiomatic waywarn
clippy::complexityCode that does something simple but in a complex waywarn
clippy::perfCode that can be written to run fasterwarn
clippy::pedanticLints which are rather strict or have occasional false positivesallow
clippy::restrictionLints which prevent the use of language and library featuresallow
clippy::nurseryNew lints that are still under developmentallow
clippy::cargoLints for the cargo manifestallow
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.

Installation

1

Install Rustup

Ensure you have rustup installed and updated:
rustup update
2

Add Clippy Component

Install Clippy as a rustup component:
rustup component add clippy
3

Run Clippy

Run Clippy on your project:
cargo clippy

Usage

Basic Usage

# Run clippy on the current crate
cargo clippy

# Automatically apply suggestions
cargo clippy --fix

# Run on all targets (bins, tests, examples)
cargo clippy --all-targets

# Run with all features enabled
cargo clippy --all-features

Workspace Support

# Run on a specific package in a workspace
cargo clippy -p example

# Run only on the specified package, excluding dependencies
cargo clippy -p example -- --no-deps

Using clippy-driver Directly

For projects that don’t use Cargo:
clippy-driver --edition 2021 -Cpanic=abort foo.rs
clippy-driver is designed for running Clippy only and should not be used as a general replacement for rustc.

Configuration

Lint Levels in Code

Control lints within your Rust code:
// 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) {
    // ...
}

Command-Line Configuration

# Allow a specific lint
cargo clippy -- -A clippy::lint_name

# Warn on a specific lint
cargo clippy -- -W clippy::lint_name

# Deny all warnings
cargo clippy -- -D warnings

# Enable pedantic lints
cargo clippy -- -W clippy::pedantic

Configuration File

Create a clippy.toml or .clippy.toml file in your project:
# clippy.toml
avoid-breaking-exported-api = false
disallowed-names = ["toto", "tata", "titi"]

# Extend default values with ".."
disallowed-names = ["bar", ".."]
clippy.toml cannot be used to allow/deny lints, only to configure their behavior.

Minimum Supported Rust Version (MSRV)

Specify MSRV to disable lints for newer features:
# clippy.toml
msrv = "1.65.0"
Or in Cargo.toml:
[package]
rust-version = "1.65"
Or as an attribute:
#![feature(custom_inner_attributes)]
#![clippy::msrv = "1.65.0"]

Building Clippy from Source

Clippy is located at src/tools/clippy/ in the Rust repository.

Package Structure

From src/tools/clippy/Cargo.toml:
[package]
name = "clippy"
version = "0.1.95"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
edition = "2024"

[[bin]]
name = "cargo-clippy"
path = "src/main.rs"

[[bin]]
name = "clippy-driver"
path = "src/driver.rs"

[dependencies]
clippy_lints = { path = "clippy_lints" }
clippy_utils = { path = "clippy_utils" }

Build with Bootstrap

# Build clippy
./x build clippy

# Test clippy
./x test clippy

# Build and test a specific lint
./x test tests/ui/my_lint.rs

Clippy Components

Clippy is organized into several crates:

clippy_lints

Contains all lint implementations. Each lint is defined and implemented here.

clippy_utils

Utility functions and helpers used by lint implementations.

clippy_config

Configuration handling and parsing for clippy.toml.

rustc_tools_util

Utilities for building rustc-based tools.

CI Integration

GitHub Actions

name: Clippy
on: [push, pull_request]

jobs:
  clippy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          components: clippy
          override: true
      - run: cargo clippy --all-targets --all-features -- -D warnings

Travis CI

language: rust
rust:
  - stable
  - beta
before_script:
  - rustup component add clippy
script:
  - cargo clippy -- -D warnings
  - cargo test

Common Lints Examples

Correctness Lints

// ❌ Bad: Incorrect use of clone
let x = Box::new(5);
let y = x.clone(); // Use *x instead

// ❌ Bad: Suspicious else formatting
if condition {
    do_something();
}
else {  // Should be on same line as closing brace
    do_other();
}

Performance Lints

// ❌ Bad: Unnecessary collect
let sum: i32 = vec.iter().collect::<Vec<_>>().iter().sum();

// ✅ Good: Direct iteration
let sum: i32 = vec.iter().sum();

// ❌ Bad: Using clone in a loop
for item in items.iter() {
    let owned = item.clone();  // Consider using references
}

Style Lints

// ❌ Bad: Redundant field names
let point = Point { x: x, y: y };

// ✅ Good: Field init shorthand
let point = Point { x, y };

// ❌ Bad: Explicit return
fn add(a: i32, b: i32) -> i32 {
    return a + b;
}

// ✅ Good: Implicit return
fn add(a: i32, b: i32) -> i32 {
    a + b
}

Disabling Specific Warnings

To disable the “for further information visit” messages:
export CLIPPY_DISABLE_DOCS_LINKS=1

Development Tools

Clippy includes several development and testing tools:
  • lintcheck: Tests Clippy against real-world crates
  • rustc_tools_util: Version and build utilities
  • clippy_dev: Development tools for adding new lints

Resources

Build docs developers (and LLMs) love