Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

rustc and Clippy Lints

Rule

Use the checked-in curated workspace lint baseline, enforce warnings in CI, and justify narrow exceptions with #[expect(..., reason = "...")].

Why

Central policy keeps the baseline consistent, while local expectations make intentional exceptions visible and auditable.

Do

  • Put shared lint levels in the workspace Cargo.toml and opt member crates into them.
  • Run cargo clippy --locked --workspace --all-targets --all-features -- -D warnings in CI.
  • Enable clippy::pedantic at warn, then centrally allow rejected noisy lints.
  • Deny correctness and project-boundary violations deliberately.
  • Put architecture-specific disallowed items in clippy.toml.
  • Use local #[expect] at the narrowest scope for justified deviations.

Avoid

  • Do not enable all restriction lints or deny all pedantic lints.
  • Do not add unexplained #[allow] attributes.
  • Do not hide a one-off exception in workspace-wide configuration.
  • Do not copy architecture-specific guardrails without checking the target project.
  • Do not weaken policy merely to unblock one implementation.

Lint Levels and CI

  • deny fails where the lint runs.
  • warn becomes an error under CI’s -D warnings.
  • allow is a real exemption and belongs in central policy only when broadly intended.

Example

#![allow(unused)]
fn main() {
#[expect(
    clippy::print_stdout,
    reason = "curated command help is written directly to stdout"
)]
fn print_help() {
    println!("usage: app <command>");
}
}

Exceptions

  • Use #[allow] when #[expect] is unavailable or generated code intentionally disables a lint.
  • Move an exception to workspace configuration only after adopting it as project policy.
  • Lower unsafe_code = "deny" only for a crate whose documented purpose requires unsafe code.