Skip to content

Commit 94db4b0

Browse files
Add check for empty cfg all condition
1 parent 5328852 commit 94db4b0

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

Diff for: clippy_lints/src/attrs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,14 @@ fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
796796
}
797797
},
798798
);
799+
} else if list.is_empty() && meta.has_name(sym::all) {
800+
span_lint_and_then(
801+
cx,
802+
NON_MINIMAL_CFG,
803+
meta.span,
804+
"unneeded sub `cfg` when there is no condition",
805+
|_| {},
806+
);
799807
}
800808
}
801809
}

Diff for: tests/ui/non_minimal_cfg.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ fn wasi() {}
1111
#[cfg(all(unix, not(windows)))]
1212
fn the_end() {}
1313

14+
#[cfg(all())]
15+
fn all() {}
16+
17+
#[cfg(any())]
18+
fn any() {}
19+
1420
fn main() {}

Diff for: tests/ui/non_minimal_cfg.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@run-rustfix
2-
31
#![allow(unused)]
42

53
#[cfg(all(windows))]
@@ -11,4 +9,10 @@ fn wasi() {}
119
#[cfg(all(any(unix), all(not(windows))))]
1210
fn the_end() {}
1311

12+
#[cfg(all())]
13+
fn all() {}
14+
15+
#[cfg(any())]
16+
fn any() {}
17+
1418
fn main() {}

Diff for: tests/ui/non_minimal_cfg.stderr

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
error: unneeded sub `cfg` when there is only one condition
2-
--> $DIR/non_minimal_cfg.rs:5:7
2+
--> $DIR/non_minimal_cfg.rs:3:7
33
|
44
LL | #[cfg(all(windows))]
55
| ^^^^^^^^^^^^ help: try: `windows`
66
|
77
= note: `-D clippy::non-minimal-cfg` implied by `-D warnings`
88

99
error: unneeded sub `cfg` when there is only one condition
10-
--> $DIR/non_minimal_cfg.rs:8:7
10+
--> $DIR/non_minimal_cfg.rs:6:7
1111
|
1212
LL | #[cfg(any(windows))]
1313
| ^^^^^^^^^^^^ help: try: `windows`
1414

1515
error: unneeded sub `cfg` when there is only one condition
16-
--> $DIR/non_minimal_cfg.rs:11:11
16+
--> $DIR/non_minimal_cfg.rs:9:11
1717
|
1818
LL | #[cfg(all(any(unix), all(not(windows))))]
1919
| ^^^^^^^^^ help: try: `unix`
2020

2121
error: unneeded sub `cfg` when there is only one condition
22-
--> $DIR/non_minimal_cfg.rs:11:22
22+
--> $DIR/non_minimal_cfg.rs:9:22
2323
|
2424
LL | #[cfg(all(any(unix), all(not(windows))))]
2525
| ^^^^^^^^^^^^^^^^^ help: try: `not(windows)`
2626

27-
error: aborting due to 4 previous errors
27+
error: unneeded sub `cfg` when there is no condition
28+
--> $DIR/non_minimal_cfg.rs:12:7
29+
|
30+
LL | #[cfg(all())]
31+
| ^^^^^
32+
33+
error: aborting due to 5 previous errors
2834

0 commit comments

Comments
 (0)