Clippy adds Rust-specific linting on top of the compiler so review can catch suspicious patterns, needless complexity, and style issues before they reach a branch or CI job. Running it through Cargo keeps the check tied to the same package or workspace manifest that developers already use for builds and tests.

A rustup-managed toolchain usually includes Clippy, but minimal profiles may need the clippy component installed for the active toolchain. cargo clippy runs the default lint set from clippy::all, and arguments after -- are passed through to Clippy and rustc lint controls.

Treat warnings as local feedback first, then make them fail in review or CI once the project is ready to enforce them. Use narrow source-level allowances such as #[allow(clippy::lint_name)] only for intentional exceptions so future warnings remain visible.

Steps to lint Rust code with Clippy:

  1. Open a terminal in the Cargo package or workspace root.

    The directory should contain the Cargo.toml file for the package, or the root manifest for the workspace.

  2. Install or confirm the Clippy component for the active toolchain.
    $ rustup component add clippy
    info: component clippy is up to date
  3. Run Clippy with the default lint set.
    $ cargo clippy
        Checking hello-clippy v0.1.0 (/home/user/hello-clippy)
    warning: length comparison to zero
     --> src/main.rs:4:8
      |
    4 |     if name.len() > 0 {
      |        ^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!name.is_empty()`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#len_zero
      = note: `#[warn(clippy::len_zero)]` on by default
    
    warning: `hello-clippy` (bin "hello-clippy") generated 1 warning (run `cargo clippy --fix --bin "hello-clippy" -p hello-clippy -- ` to apply 1 suggestion)
        Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

    cargo clippy exits successfully for ordinary warnings. Read the first file and line before chasing later warnings, because one issue can trigger related diagnostics.

  4. Fix the reported source line or allow the lint in the narrowest useful scope.
    if !name.is_empty() {
        println!("{name}");
    }

    Prefer changing the code when the suggestion matches the project style. Use #[allow(clippy::len_zero)] on the smallest item, function, or module only when the warning is intentionally accepted.

  5. Run strict Clippy before review or CI.
    $ cargo clippy --all-targets -- -D warnings
        Checking hello-clippy v0.1.0 (/home/user/hello-clippy)
        Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s

    --all-targets includes tests, benches, examples, library targets, and binaries. Add --all-features, --features, or --no-default-features when the project uses feature combinations that CI also checks.