-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[needless_continue
]: lint if the last stmt in for/while/loop is `co…
#11546
Conversation
r? @xFrednet (rustbot has picked a reviewer for you, use r? to override) |
821e055
to
a403969
Compare
This would be another good one to look at @y21 |
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.
Just a few things, other than that it looks good to me!
a403969
to
5493578
Compare
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.
I believe the lint description could also use an update now that it lints additional cases and no longer just if
exprs.
0bf5d42
to
4a45997
Compare
Hey @lengyijun, the CI failed on your last commit. Do you need any help to address the issue? :) |
1d85d1b
to
d890421
Compare
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.
Looks good to me!
d890421
to
a773ed0
Compare
…ntinue`, recursively fixes: rust-lang#4077
a773ed0
to
9f999e9
Compare
@bors delegate=y21 I think a good follow up to this if you're interested would be to split this lint up, this addition should be warn by default IMO but the lint is currently |
✌️ @y21, you can now approve this pull request! If @Alexendoo told you to " |
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.
I looked through this one last time and found a potential edge case I wanted to mention (sorry! 😅)
} | ||
}; | ||
check_last_stmt_in_block(loop_block, &p); | ||
|
||
for (i, stmt) in loop_block.stmts.iter().enumerate() { |
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.
Right now it's possible for the same lint to emit two warnings for the following code:
loop {
if true {
} else { // redundant `else`
continue; // redundant `continue`
}
}
Output
warning: this `continue` expression is redundant
--> test.rs:171:13
|
171 | continue;
| ^^^^^^^^
warning: this `else` block is redundant
--> test.rs:170:16
|
170 | } else {
| ________________^
171 | | continue;
172 | | }
| |_________^
|
I like the other warning a bit more in this case because it suggests removing the whole else
block altogether.
@Alexendoo What do you think? Is this fine to ignore for now or would you consider it a potential blocker? Looks like it possibly has a bit of overlap with your suggestion to split up the lint
If this is a good idea and worth fixing in this PR, we could probably just move this check_last_stmt_in_expr
call into the loop and guard it behind an i == stmts.len() - 1
check so that it only runs on the last statement, inline the with_if_expr
function (it's really short and only used here, anyway) and add continue;
in the one lint case that is emitted here so that it skips checking the new case.
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.
Yeah, good catch, we don't want to be linting the same thing twice
The else winning would be preferable, but if it's easier implementation wise to ignore it that's fine too, there's a lint for empty else blocks that would pick it up
☔ The latest upstream changes (presumably #11750) made this pull request unmergeable. Please resolve the merge conflicts. |
Hey @lengyijun, this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation? If you have any questions, you're always welcome to ask them in this PR or on Zulip. @rustbot author |
Hey this is triage, I'm closing this due to inactivity. If you want to continue this implementation, you're welcome to create a new PR. Thank you for the time, you already put into this! Interested parties are welcome to pick this implementation up as well :) @rustbot label +S-inactive-closed -S-waiting-on-author -S-waiting-on-review |
changelog: [
needless_continue
]: lint if the last stmt in for/while/loop iscontinue
, recursivelyFixes: #4077