rust-lang / rust-lang/rust-clippy
Lint suggestion: `cfg!(not(...))` vs `!cfg!(...)`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Essentially, warn on cases that use cfg!(not(...)) instead of !cfg!(...).
Advantage
This could also be combined with other lints so that boolean simplification can be applied to cfgs, meaning that something like cfg(any(not(...), not(...)) could be simplified to !cfg(all(..., ...)).
Drawbacks
Maybe this is too pedantic to be enabled by default. There are also cases where someone might prefer the more verbose version for clarity, and maybe the lint would need to offer both.
Example
if cfg!(not(feature = "optimize_for_size")) {
// ...
}
Could be written as:
if !cfg!(feature = "optimize_for_size") {
// ...
}
Future extensions
Perhaps there could be other expansions on this too, like converting all(...) and any(...) into separate cfg! statements:
if cfg!(any(windows, unix)) {
// ...
}
Could be written as:
if cfg!(windows) || cfg!(unix) {
// ...
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation files or tests are named. Start by reviewing the requested cfg!(not(...)) versus !cfg!(...) examples and defining the lint's scope and default status; done means the intended cases are linted with an appropriate suggestion and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100