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.tomland opt member crates into them. - Run
cargo clippy --locked --workspace --all-targets --all-features -- -D warningsin CI. - Enable
clippy::pedanticatwarn, 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
denyfails where the lint runs.warnbecomes an error under CI’s-D warnings.allowis 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.