Skip to content

Commit

Permalink
Add check for empty cfg all and any conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 19, 2023
1 parent 5328852 commit e3ad36c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
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() {
span_lint_and_then(
cx,
NON_MINIMAL_CFG,
meta.span,
"unneeded sub `cfg` when there is no condition",
|_| {},
);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/non_minimal_cfg.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ fn wasi() {}
#[cfg(all(unix, not(windows)))]
fn the_end() {}

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

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

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

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

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

fn main() {}
14 changes: 13 additions & 1 deletion tests/ui/non_minimal_cfg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,17 @@ error: unneeded sub `cfg` when there is only one condition
LL | #[cfg(all(any(unix), all(not(windows))))]
| ^^^^^^^^^^^^^^^^^ help: try: `not(windows)`

error: aborting due to 4 previous errors
error: unneeded sub `cfg` when there is no condition
--> $DIR/non_minimal_cfg.rs:14:7
|
LL | #[cfg(all())]
| ^^^^^

error: unneeded sub `cfg` when there is no condition
--> $DIR/non_minimal_cfg.rs:17:7
|
LL | #[cfg(any())]
| ^^^^^

error: aborting due to 6 previous errors

0 comments on commit e3ad36c

Please sign in to comment.