clippy: deny warnings, allow, and lint levels
Clippy lints have four levels (allow, warn, deny, forbid) set by attributes, command-line flags, or a clippy.toml file.
The deny/allow controls decide which lints fail the build. You set them broadly with flags and groups, or narrowly with attributes.
What it does
A lint at deny becomes an error; at allow it is silenced. You raise the whole crate with -D warnings, target groups like clippy::pedantic, or individual lints. Source attributes (#[allow(clippy::too_many_arguments)]) override for a scope.
Common usage
# deny all warnings, then re-allow one lint
cargo clippy -- -D warnings -A clippy::needless_return
# opt into the pedantic group as warnings
cargo clippy -- -W clippy::pedantic
# crate-wide attribute, in lib.rs / main.rs
#![deny(clippy::all)]Flags and attributes
| Form | What it does |
|---|---|
| -D <lint> | Deny: the lint becomes a build error |
| -W <lint> | Warn: report but do not fail |
| -A <lint> | Allow: silence the lint |
| -F <lint> | Forbid: deny and block any later allow |
| clippy::all / pedantic / nursery | Lint groups you can set a level on |
| #[allow(clippy::name)] | Per-item override in source |
In CI
Prefer setting -D warnings on the command line over a hard-coded #![deny(warnings)] in source: the attribute makes every future compiler warning a hard error too, so a new rustc release can break builds that have not changed. Keep the deny in CI, not the crate.
Common errors in CI
"error: unknown lint: clippy::xyz" means a renamed or removed lint; check the Clippy lint list for the current name. "the lint level is defined here" in the error trail points at which attribute or flag promoted the warning. A lint set to forbid cannot be re-allowed and will error if an #[allow] tries.