Skip to content

Commit dbc76a7

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

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
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

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

14+
#[cfg(any())]
15+
fn any() {}
16+
1417
fn main() {}

Diff for: tests/ui/non_minimal_cfg.rs

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

14+
#[cfg(any())]
15+
fn any() {}
16+
1417
fn main() {}

Diff for: tests/ui/non_minimal_cfg2.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(unused)]
2+
3+
#[cfg(all())]
4+
fn all() {}
5+
6+
fn main() {}

Diff for: tests/ui/non_minimal_cfg2.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unneeded sub `cfg` when there is no condition
2+
--> $DIR/non_minimal_cfg2.rs:3:7
3+
|
4+
LL | #[cfg(all())]
5+
| ^^^^^
6+
|
7+
= note: `-D clippy::non-minimal-cfg` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)