# What is Clippy, and how do I fix or silence its warnings?
Source: https://ruststudio.org/community/t/119/what-is-clippy-and-how-do-i-fix-or-silence-its-warnings
Author: Ruststudio Team (staff) | Published: 2026-12-05 | Updated: 2026-12-05 | Checked with: rustc 1.93.0 and clippy 1.93.0, Windows 11
Category: Help and questions | Kind: FAQ | Tags: clippy, cargo, tooling | Views: 0

## Short answer
Clippy is Rust's official linter. It runs after the compiler and points out code that compiles but is unidiomatic, slower than needed or likely wrong. Run cargo clippy, fix what it reports, add -- -D warnings to make warnings fail CI, and silence a single lint with #[allow(...)] only with a reason.

## Answer
## Answer
Clippy checks code the compiler accepts. It knows hundreds of patterns, such as an index loop that an iterator would do better, or comparing `len() == 0` instead of calling `is_empty()`. Every message names the lint and says how to fix it.

## How to do it
1. Take this program. It compiles, but is not written the way Rust code usually is.

```rust title=src/main.rs
fn total(values: &Vec<i32>) -> i32 {
    let mut sum = 0;
    for i in 0..values.len() {
        sum += values[i];
    }
    sum
}

fn main() {
    let values = vec![1, 2, 3];
    if values.len() == 0 {
        println!("empty");
    }
    println!("{}", total(&values));
}
```

2. Run Clippy.

```text
> cargo clippy
warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
 --> src\main.rs:1:18
  |
1 | fn total(values: &Vec<i32>) -> i32 {
  |                  ^^^^^^^^^ help: change this to: `&[i32]`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#ptr_arg
  = note: `#[warn(clippy::ptr_arg)]` on by default

warning: the loop variable `i` is only used to index `values`
 --> src\main.rs:3:14
  |
3 |     for i in 0..values.len() {
  |              ^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#needless_range_loop
  = note: `#[warn(clippy::needless_range_loop)]` on by default
help: consider using an iterator
  |
3 -     for i in 0..values.len() {
3 +     for <item> in &values {
  |

warning: length comparison to zero
  --> src\main.rs:11:8
   |
11 |     if values.len() == 0 {
   |        ^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `values.is_empty()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#len_zero
   = note: `#[warn(clippy::len_zero)]` on by default

warning: `lint` (bin "lint") generated 3 warnings (run `cargo clippy --fix --bin "lint" -p lint` to apply 1 suggestion)
```

3. Apply the suggestions. Many can be applied automatically with `cargo clippy --fix`, which edits the files, so commit your work first.
4. In CI, turn warnings into errors so they cannot be ignored:

```text
> cargo clippy -- -D warnings
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
 --> src\main.rs:1:18
  |
1 | fn total(values: &Vec<i32>) -> i32 {
  |                  ^^^^^^^^^ help: change this to: `&[i32]`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#ptr_arg
  = note: `-D clippy::ptr-arg` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]`

error: the loop variable `i` is only used to index `values`
 --> src\main.rs:3:14
  |
3 |     for i in 0..values.len() {
  |              ^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#needless_range_loop
  = note: `-D clippy::needless-range-loop` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]`
help: consider using an iterator
  |
3 -     for i in 0..values.len() {
3 +     for <item> in &values {
  |

error: length comparison to zero
  --> src\main.rs:11:8
   |
11 |     if values.len() == 0 {
   |        ^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `values.is_empty()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#len_zero
   = note: `-D clippy::len-zero` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::len_zero)]`

error: could not compile `lint` (bin "lint") due to 3 previous errors
exit: 101
```

## Why it works
Clippy is a compiler driver: it runs the normal compiler passes and adds its own lint passes on the result, which is why it needs a project that builds. Lints are grouped by how sure they are; the default set warns (`clippy::all`), and the stricter groups such as `pedantic` are off until you ask for them.

## Common mistakes
- Silencing a lint everywhere with `#![allow(clippy::all)]`. Allow one lint, on one item, and say why in a comment:

```rust
#[allow(clippy::too_many_arguments)] // mirrors the C API one to one
fn open(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8, g: u8, h: u8) {}
```

- Treating each lint as an order. A few are matters of taste; the explanation link in each message says why the lint exists.
- Running Clippy on code that does not compile. Fix the compiler errors first.

## In Ruststudio
Run > Clippy Lints runs `cargo clippy` and shows the results in the Problems list, and Run > Cargo: Apply Clippy Fixes runs `cargo clippy --fix` with `--allow-dirty --allow-staged`. Because that changes files, commit or save your work before using it.
