Add check for empty cfg `all` condition

This commit is contained in:
Guillaume Gomez 2023-05-19 16:23:17 +02:00
parent 5328852ad7
commit dbc76a7663
5 changed files with 30 additions and 0 deletions

View File

@ -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",
|_| {},
);
}
}
}

View File

@ -11,4 +11,7 @@ fn wasi() {}
#[cfg(all(unix, not(windows)))]
fn the_end() {}
#[cfg(any())]
fn any() {}
fn main() {}

View File

@ -11,4 +11,7 @@ fn wasi() {}
#[cfg(all(any(unix), all(not(windows))))]
fn the_end() {}
#[cfg(any())]
fn any() {}
fn main() {}

View File

@ -0,0 +1,6 @@
#![allow(unused)]
#[cfg(all())]
fn all() {}
fn main() {}

View File

@ -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