Lint Levels & Attributes
Rust lints can be allowed, warned, denied, or forbidden at crate, module, or item level. Cargo.toml [lints] tables centralize policy for rustc and clippy.
Search across all documentation pages
Rust lints can be allowed, warned, denied, or forbidden at crate, module, or item level. Cargo.toml [lints] tables centralize policy for rustc and clippy.
[lints.rust]
unsafe_code = "forbid"
missing_docs = "warn"
[lints.clippy]
all = "warn"
pedantic = "allow"#[deny(clippy::unwrap_used)]
fn production_path() { }When to reach for this: Crate-wide safety policy, tightening warnings-as-errors, or targeted exceptions.
#![deny(unsafe_code)]
#![warn(missing_docs)]
mod api {
#![allow(clippy::module_name_repetitions)]
/// Creates a user.
pub fn create_user() { }
}# Cargo.toml alternative to inner attributes
[lints.rust]
unsafe_code = "forbid"What this demonstrates:
#![...] on modules scope subtreeforbid cannot be overridden downstream (strongest)[lints] preferred for workspace consistency| Level | Behavior |
|---|---|
allow | Silent |
warn | Warning, build succeeds |
deny | Error |
forbid | Error; cannot allow in children |
[lints.rust]
unused_must_use = "deny"
[lints.clippy]
unwrap_used = "deny" # apps: deny; libs: warnwarn on unwrap in public APIdeny unwrap_used in non-test code#![deny(warnings)] without policy - breaks on new Rust warnings after upgrade. Fix: pin toolchain; fix warnings promptly on bump.forbid then allow in submodule - compile error. Fix: use deny if children need exceptions.clippy::all - disables valuable checks. Fix: allow specific lints only.unwrap in tests is fine. Fix: #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] }.| Alternative | Use When | Don't Use When |
|---|---|---|
CI -D warnings only | No manifest support needed | Per-crate policy differences |
cargo clippy -- -W lint | Experiment locally | Permanent policy |
#[expect(lint)] (nightly) | Suppress with intent tracking | Stable MSRV 1.97 teams use allow |
Libs often warn; bins/services deny for production rigor.
Each crate has own [lints]; share via copy or workspace lint table future patterns - document in CONTRIBUTING.
Usually public items only; configure missing_docs on pub via clippy/rustc docs.
RUSTFLAGS and clippy args add warnings; manifest still applies as base.
Set on domain crates; allow single ffi crate with documented safety reviews.
#[allow(clippy::lint)] on fn or statement.
New rustc lints may warn; run cargo fix and clippy after toolchain upgrade.
Separate compilation unit; set lints in build.rs crate attributes if needed.
clippy::all, clippy::pedantic - enable groups then allow noisy subsets.
ARCHITECTURE.md or CONTRIBUTING: unsafe, unwrap, missing_docs expectations.
-D warningsStack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Reviewed by Chris St. John·Last updated Jul 16, 2026