-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Disable "if_not_else" lints from firing on else-ifs #7895
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. Please see the contribution instructions for more information. |
@bors r+ |
📌 Commit 282d313 has been approved by |
Disable "if_not_else" lints from firing on else-ifs Fixes #7892 1. Convert `['if_not_else']` to `LateLintPass` and use `clippy_utils::is_else_clause` for checking. 2. Update tests.
@bors r- CI is failing |
💔 Test failed - checks-action_test |
The error can be seen here It looks like a false positive, it might have something to do with how while loops are desugared 🤔 Could you also include a changelog entry in your PR, the CI will otherwise fail during the merge. You can just add something like this: "changelog: [ |
This might makes sense since it's now using a late pass rather than an early pass |
Yes, but it seems weird that |
Thanks @Manishearth, @xFrednet and @dswij!
@xFrednet, I've removed the |
That's good to know! Reach out, if you need more help debugging 🙃 |
clippy_lints/src/if_not_else.rs
Outdated
if in_external_macro(cx.sess, item.span) { | ||
impl LateLintPass<'_> for IfNotElse { | ||
fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) { | ||
if in_external_macro(cx.sess(), item.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 will fix it if my suspicion is right - changing to LateLintPass means that desugaring occurs before the lint runs. from_expansion
will catch desugaring in addition to macros.
if in_external_macro(cx.sess(), item.span) { | |
if item.span.from_expansion() { |
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.
Thanks @camsteffen. This is my first time working with rustc. I didn't know this life saver function existed!
I've been debugging the issue. After dumping the expression trees, I could see that the while loop was indeed represented as an ExprKind::If
when using LateLintPass
which caused this problem. I thought about reverting back to EarlyLintPass
and looking for a workaround, but your comment came just in time!
1. Convert IfNotElse to LateLintPass and use clippy_utils::is_else_clause for checking. 2. Handle the case where the span comes from desugaring. 3. Update tests.
@bors r+ |
📌 Commit 2f327aa has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #7892
['if_not_else']
toLateLintPass
and useclippy_utils::is_else_clause
for checking.changelog: [
if_not_else
] now ignores else if statements.