-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
add unreachable_cfg_select_predicates lint
#149960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
|
rustbot has assigned @WaffleLapkin. Use |
|
The proposed name for this lint seems quite unfortunate to me. When I first read it I though it had something to do with the I think it would be better include the word "arm" or "cfg_select" in it, to clearly disambiguate it from the other places where cfgs can appear. Maybe |
|
There is some reasoning for then name at #149783 (comment). cc @traviscross was there any particular reason for you to leave out the select or arm/branch parts? |
|
The reasoning was: For Here that would suggest the name But we have an existing lint, To your point about detecting Sitting with it now, though, I think |
|
☔ The latest upstream changes (presumably #146348) made this pull request unmergeable. Please resolve the merge conflicts. |
542a992 to
20f27e5
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. |
unreachable_cfgs lintunreachable_cfg_select_predicates lint
|
I do like |
| if let Some((underscore, _, _)) = branches.wildcard | ||
| && features.map_or(false, |f| f.enabled(rustc_span::sym::cfg_select)) | ||
| { | ||
| for (predicate, _, _) in &branches.unreachable { | ||
| let span = predicate.span(); | ||
| p.psess.buffer_lint( | ||
| UNREACHABLE_CFG_SELECT_PREDICATES, | ||
| span, | ||
| lint_node_id, | ||
| BuiltinLintDiag::UnreachableCfg { span, wildcard_span: underscore.span }, | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to warn, unless there is a wildcard, why so? Does it not warn in case of
cfg_select! {
unix => true,
not(unix) => false,
windows => false,
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct, it's hard to do better than that. we'd need to actually have some sort of logic solver to do so in general, and even then I think it might misfire if there is some sort of feature flag implication that the checker does not know about.
So the current imlementation is basic but reliable.
|
@rustbot ready |
20f27e5 to
288443c
Compare
This comment has been minimized.
This comment has been minimized.
This is emitted on branches of a `cfg_select!` that are statically known to be unreachable.
288443c to
d333d5e
Compare
tracking issue: #115585
Split out from #149783. This lint is emitted on branches of a
cfg_select!that are statically known to be unreachable. The lint is only emitted when the feature is enabled, so this change specifically does not need an FCP, and the lint will be stabilized alongside the feature (see #149783 (comment)).