Lint against empty cfg(any()/all())#158136
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
|
r? @Kivooeo rustbot has assigned @Kivooeo. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
55a90d0 to
9cc7a12
Compare
|
cc @rust-lang/miri |
|
Does this lint fire if the cfg predicate is produced in a macro expansion? I can see some valid use cases for producing |
No; if list.is_empty() && !list.span.from_expansion() {gates the emission. |
This comment has been minimized.
This comment has been minimized.
9cc7a12 to
a32f57f
Compare
|
cc @rust-lang/clippy |
|
This does overlap somewhat with |
|
Reminder, once the PR becomes ready for a review, use |
a32f57f to
4248898
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| /// `cfg(false)` and `cfg(true)` respectively may be used instead. | ||
| /// This used to be a common pattern before `cfg(true)` and `cfg(false)` | ||
| /// were added to the language in Rust 1.88 | ||
| pub EMPTY_CFG_PREDICATE, |
There was a problem hiding this comment.
| pub EMPTY_CFG_PREDICATE, | |
| pub EMPTY_CFG_PREDICATES, |
Per our RFC 0344 guidance, this should be in the plural.
Also, the naming seems a bit loose. This is targeting two specific cfg predicates, not empty cfg predicates in general (and, of course, we might later add more cfg predicates that we might not want to lint when empty). Have any more targeted ideas for a name?
There was a problem hiding this comment.
Maybe EMPTY_CFG_COMBINATORS? Or EMPTY_CFG_LISTS (but that's a little less precise)
Detect usages of
cfg(any())andcfg(all())and suggest the literal boolean equivalents. When--lint-rust-versionis available, gate the diagnostic appropriately.Will need to be updated for #158134
Implements the lint suggested in rust-lang/rfcs#3695 (Tracking: #131204)
Tracking issue: #157574