Skip to content

Commit e3ad36c

Browse files
Add check for empty cfg all and any conditions
1 parent 5328852 commit e3ad36c

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
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() {
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
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ fn wasi() {}
1111
#[cfg(all(any(unix), all(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.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,17 @@ error: unneeded sub `cfg` when there is only one condition
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:14:7
29+
|
30+
LL | #[cfg(all())]
31+
| ^^^^^
32+
33+
error: unneeded sub `cfg` when there is no condition
34+
--> $DIR/non_minimal_cfg.rs:17:7
35+
|
36+
LL | #[cfg(any())]
37+
| ^^^^^
38+
39+
error: aborting due to 6 previous errors
2840

0 commit comments

Comments
 (0)