-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #![warn(unreachable_cfg_select_predicates)] // Unused warnings are disabled by default in UI tests. | ||
|
|
||
| // `#[feature(cfg_select)]` is a libs feature (so, not a lang feature), but it lints on unreachable | ||
| // branches, and that lint should only be emitted when the feature is enabled. | ||
|
Comment on lines
+3
to
+4
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: why should it only lint when the feature is enabled?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because then no separate FCP is required to merge this lint. At least that is my interpretation of #149783 (comment).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably what I had in mind is to go ahead and make it into (or otherwise add) a lang feature gate and then to feature gate the lint itself in the |
||
|
|
||
| cfg_select! { | ||
| //~^ ERROR use of unstable library feature `cfg_select` | ||
| _ => {} | ||
| // With the feature enabled, this branch would trip the unreachable_cfg_select_predicate lint. | ||
| true => {} | ||
| } | ||
|
|
||
| fn main() {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| error[E0658]: use of unstable library feature `cfg_select` | ||
| --> $DIR/cfg_select.rs:6:1 | ||
| | | ||
| LL | cfg_select! { | ||
| | ^^^^^^^^^^ | ||
| | | ||
| = note: see issue #115585 <https://github.com/rust-lang/rust/issues/115585> for more information | ||
| = help: add `#![feature(cfg_select)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0658`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -431,3 +431,21 @@ note: the lint level is defined here | |
| LL | #![forbid(forbidden_lint_groups)] | ||
| | ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Future breakage diagnostic: | ||
| error: warn(unused) incompatible with previous forbid | ||
| --> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:22:13 | ||
| | | ||
| LL | #![forbid(unused)] | ||
| | ------ `forbid` level set here | ||
| LL | #![deny(unused)] | ||
| LL | #![warn(unused)] | ||
| | ^^^^^^ overruled by previous forbid | ||
| | | ||
| = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
| = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670> | ||
| note: the lint level is defined here | ||
| --> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:17:11 | ||
| | | ||
| LL | #![forbid(forbidden_lint_groups)] | ||
| | ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
|
Comment on lines
+434
to
+451
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened, how is this change related?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test has this comment I believe that the logic here added another time that the error is emitted. That's unfortunate but as the comment mentions it's kind of not worth the engineering effort to fix because it is unlikely that end users ever see this repeated error. |
||
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
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.