Skip to content

C0002 allow-without-reason

Rule: Every allow or expect of a lint says why.

Code C0002 (stable, never reused)
Id allow-without-reason
Category code
Source spirit_level
Fix by hand

Level per tier

Tier Level Reason
small warn an exception to a lint says why, or it outlives its reason
small-workspace warn an exception to a lint says why, or it outlives its reason
medium warn an exception to a lint says why, or it outlives its reason
big deny an exception to a lint says why, or it outlives its reason
ai deny an allowed lint says why, so it can be turned back on
embedded off
ui off
egui off
units-strict off
units-paranoid off

Why

An #[allow(...)] silences a lint where a person decided it does not apply. Without the reason the next reader cannot tell a considered exception from a silenced warning, and it outlives the code it was for. Rust's reason = "..." field (and #[expect], which fails once the lint no longer fires) keep the exception honest. Test code is checked too.

How to fix

#[expect(clippy::too_many_arguments, reason = "mirrors the C API one to one")]

Clippy

Clippy's allow_attributes (in the medium, big and ai tiers' Clippy set) goes further: it refuses #[allow] altogether in favour of #[expect]. This lint stays on beside it: it also wants a reason on #[expect], and runs without building the code.

Configure

[lints.allow-without-reason]
level = "deny"
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(allow-without-reason) <reason> (waivers); the code works there too, as in [lints.C0002].