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)
There was a problem hiding this comment.
That's probably my preferred suggestion so far (or MANUAL_CFG_BOOLS?), but open to others
This comment was marked as outdated.
This comment was marked as outdated.
|
My take is:
I would like us to develop checklists and guidelines. We've tried a few times. We should just put something on the lang-team page and adjust it over time. I think there is generally settled precedent that... Warn-by-default:
Deny-by-default:
Allow-by-default:
None of these categories covers this lint. But I think there is another category of lint that may merit warn-by-default, which is to nudge people away from older style. This was compared in the meeting to an edition idiom lint, which makes sense to me, I think edition idiom lints probably could or should be warn-by-default in the new editions in the same way. |
|
Personally I think putting our "thumb on the scale" to push people to adopt "new and better Rust" is a good idea, it benefits the whole ecosystem if there is a consistent idiomatic Rust and not a wide spread of usage. Many long-time Rust users will not learn about features any other way. I think this is why we warn for key stylistic conventions as well. I do think clippy, in practice, largely serves this purpose though -- e.g., for consistency, we may want to flag on failure to use |
|
Try this again... @rfcbot fcp merge lang We discussed this in the lang-team meeting. Everyone agreed the newer style is better. There was some question about how far we want to go in stylistic lints and where the line between rustc and clippy falls. I'm moving to merge to help move the discussion forward. @traviscross mentioned in the meeting that he would raise a concern about finalizing the naming, which makes sense. I think he or others may also raise a concern to talk about the bigger question (I'll give my thoughts on that separately). |
|
@nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot concern naming There's an open discussion on the name for this in #158136 (comment). Since the name is part of what we accept in the FCP, I'd like to let this settle first. |
|
@rfcbot concern consistency-and-plan This lint goes beyond what we normally do with warn-by-default rustc lints. It's not linting against a likely bug or typographical error. It's not pushing a key stylistic convention, such as capitalization, that we lean on as a language matter. It's not something with unclear or shifting semantics that we're trying to drive out of the language. It's a minor stylistic point. I'm not sure that we should light up CI for people on this. That said, I agree that it can sometimes make sense to push our perspective on preferred usage with linting. If we want to absorb more of Clippy into rustc by creating appropriate lint groups and discussing whether lints in those groups should be allow-by-default or warn-by-default, I'm open to that. I'd want to finish that discussion first and agree on a plan (probably in the form of an RFC) before accepting lints that break from our established conventions and only make sense in that world. |
|
In today's lang meeting I mentioned waiting for |
View all comments
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