Skip to content

Commit

Permalink
Add check for empty cfg all condition
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 19, 2023
1 parent 5328852 commit dbc76a7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
|_| {},
);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/non_minimal_cfg.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ fn wasi() {}
#[cfg(all(unix, not(windows)))]
fn the_end() {}

#[cfg(any())]
fn any() {}

fn main() {}
3 changes: 3 additions & 0 deletions tests/ui/non_minimal_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ fn wasi() {}
#[cfg(all(any(unix), all(not(windows))))]
fn the_end() {}

#[cfg(any())]
fn any() {}

fn main() {}
6 changes: 6 additions & 0 deletions tests/ui/non_minimal_cfg2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(unused)]

#[cfg(all())]
fn all() {}

fn main() {}
10 changes: 10 additions & 0 deletions tests/ui/non_minimal_cfg2.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dbc76a7

Please sign in to comment.