[needless_continue
]: lint if the last stmt in for/while/loop is `co… by lengyijun · Pull Request #11546 · rust-lang/rust-clippy (original) (raw)
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.