diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 6678002820ac..206a6ec635fa 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -796,6 +796,14 @@ fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) { } }, ); + } else if list.is_empty() { + span_lint_and_then( + cx, + NON_MINIMAL_CFG, + meta.span, + "unneeded sub `cfg` when there is no condition", + |_| {}, + ); } } } diff --git a/tests/ui/non_minimal_cfg.fixed b/tests/ui/non_minimal_cfg.fixed index ca9a48a3e377..96e660746168 100644 --- a/tests/ui/non_minimal_cfg.fixed +++ b/tests/ui/non_minimal_cfg.fixed @@ -11,4 +11,10 @@ fn wasi() {} #[cfg(all(unix, not(windows)))] fn the_end() {} +#[cfg(all())] +fn all() {} + +#[cfg(any())] +fn any() {} + fn main() {} diff --git a/tests/ui/non_minimal_cfg.rs b/tests/ui/non_minimal_cfg.rs index bf322236fef7..eea337fcc9e2 100644 --- a/tests/ui/non_minimal_cfg.rs +++ b/tests/ui/non_minimal_cfg.rs @@ -11,4 +11,10 @@ fn wasi() {} #[cfg(all(any(unix), all(not(windows))))] fn the_end() {} +#[cfg(all())] +fn all() {} + +#[cfg(any())] +fn any() {} + fn main() {} diff --git a/tests/ui/non_minimal_cfg.stderr b/tests/ui/non_minimal_cfg.stderr index cdfd728aa611..540d1f362609 100644 --- a/tests/ui/non_minimal_cfg.stderr +++ b/tests/ui/non_minimal_cfg.stderr @@ -24,5 +24,17 @@ error: unneeded sub `cfg` when there is only one condition LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^^^^^^^^^ help: try: `not(windows)` -error: aborting due to 4 previous errors +error: unneeded sub `cfg` when there is no condition + --> $DIR/non_minimal_cfg.rs:14:7 + | +LL | #[cfg(all())] + | ^^^^^ + +error: unneeded sub `cfg` when there is no condition + --> $DIR/non_minimal_cfg.rs:17:7 + | +LL | #[cfg(any())] + | ^^^^^ + +error: aborting due to 6 previous errors