diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-05-19 16:23:17 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-05-20 00:37:08 +0200 |
| commit | dbc76a766333bf510de601111f31e3eb42fb0434 (patch) | |
| tree | 1ac337ab5fc050d60531257a3cdc5ac61f061e49 | |
| parent | 5328852ad7d6801acd03eefc8bc88c3ee70929b5 (diff) | |
| download | rust-dbc76a766333bf510de601111f31e3eb42fb0434.tar.gz rust-dbc76a766333bf510de601111f31e3eb42fb0434.zip | |
Add check for empty cfg `all` condition
| -rw-r--r-- | clippy_lints/src/attrs.rs | 8 | ||||
| -rw-r--r-- | tests/ui/non_minimal_cfg.fixed | 3 | ||||
| -rw-r--r-- | tests/ui/non_minimal_cfg.rs | 3 | ||||
| -rw-r--r-- | tests/ui/non_minimal_cfg2.rs | 6 | ||||
| -rw-r--r-- | tests/ui/non_minimal_cfg2.stderr | 10 |
5 files changed, 30 insertions, 0 deletions
diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 6678002820a..897495ba108 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() && meta.has_name(sym::all) { + 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 ca9a48a3e37..430caafb33e 100644 --- a/tests/ui/non_minimal_cfg.fixed +++ b/tests/ui/non_minimal_cfg.fixed @@ -11,4 +11,7 @@ fn wasi() {} #[cfg(all(unix, not(windows)))] fn the_end() {} +#[cfg(any())] +fn any() {} + fn main() {} diff --git a/tests/ui/non_minimal_cfg.rs b/tests/ui/non_minimal_cfg.rs index bf322236fef..a38ce1c21d6 100644 --- a/tests/ui/non_minimal_cfg.rs +++ b/tests/ui/non_minimal_cfg.rs @@ -11,4 +11,7 @@ fn wasi() {} #[cfg(all(any(unix), all(not(windows))))] fn the_end() {} +#[cfg(any())] +fn any() {} + fn main() {} diff --git a/tests/ui/non_minimal_cfg2.rs b/tests/ui/non_minimal_cfg2.rs new file mode 100644 index 00000000000..a4c6abce387 --- /dev/null +++ b/tests/ui/non_minimal_cfg2.rs @@ -0,0 +1,6 @@ +#![allow(unused)] + +#[cfg(all())] +fn all() {} + +fn main() {} diff --git a/tests/ui/non_minimal_cfg2.stderr b/tests/ui/non_minimal_cfg2.stderr new file mode 100644 index 00000000000..2a9a36fbcef --- /dev/null +++ b/tests/ui/non_minimal_cfg2.stderr @@ -0,0 +1,10 @@ +error: unneeded sub `cfg` when there is no condition + --> $DIR/non_minimal_cfg2.rs:3:7 + | +LL | #[cfg(all())] + | ^^^^^ + | + = note: `-D clippy::non-minimal-cfg` implied by `-D warnings` + +error: aborting due to previous error + |
