Clippy lints / Suspicious
Clippy lint · Suspicious · checked with Clippy 0.1.99
clippy::unnecessary_clippy_cfg: no need to put clippy lints behind a `clippy` cfg
What it meansChecks for #[cfg_attr(clippy, allow(clippy::lint))] and suggests to replace it with #[allow(clippy::lint)]. It is in the suspicious group and warns by default.
What you see
warning: no need to put clippy lints behind a `clippy` cfg --> main.rs:1:1 | 1 | #![cfg_attr(clippy, allow(clippy::deprecated_cfg_attr))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![allow(clippy::deprecated_cfg_attr)]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#unnecessary_clippy_cfg = note: `#[warn(clippy::unnecessary_clippy_cfg)]` on by default
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
There is no reason to put clippy attributes behind a clippy cfg as they are not run by anything else than clippy.
Code that is most likely wrong or useless. Warns by default.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
#![cfg_attr(clippy, allow(clippy::deprecated_cfg_attr))]
Write this instead
#![allow(clippy::deprecated_cfg_attr)]
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::unnecessary_clippy_cfg)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
unnecessary_clippy_cfg = "allow"One run
cargo clippy -- -A clippy::unnecessary-clippy-cfgThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for #[cfg_attr(clippy, allow(clippy::lint))]
and suggests to replace it with #[allow(clippy::lint)].
Why is this bad?
There is no reason to put clippy attributes behind a clippy cfg as they are not
run by anything else than clippy.
Example
#![cfg_attr(clippy, allow(clippy::deprecated_cfg_attr))]
Use instead:
#![allow(clippy::deprecated_cfg_attr)]
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- test_attr_in_doctestunit tests in doctest are not executed
- type_id_on_boxcalling `.type_id()` on `Box<dyn Any>`
- unconditional_recursionfunction cannot return without recursing
- unnecessary_option_map_or_elseunused "map closure" when calling `Option::map_or_else` value
- unnecessary_result_map_or_elseChecks for usage of .map_or_else() “map closure” for Result type
- zero_repeat_side_effectsexpression with side effects as the initial value in a zero-sized array initializer
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::test_attr_in_doctestunit tests in doctest are not executedRead it next →Did this answer your question?