Description
Summary
Summary:
clippy::while_let_loop
suggests a replacement where the body of the if is not included. Note thatcargo clippy --fix
doesn't update anything- rust-analyzer sees the suggestion and ends up removing the body of the
if
when user doesn't fully comprehend the suggested action
Unknown if while_let_loop is the only clippy lint to include this behaviour (incomplete suggested replacement)
Some clippy replacements are incomplete. They provide a template for the suggested output, but direct copy paste will not give equivalent/improved behaviour. Some sections are left to the user to fill in
A simple example is the
clippy::while_let_loop
lint (I feel like it's not the only one, but perhaps I just keep running into the same issue)
clippy correctly identifies this as an opportunity to suggest a while-let loop
Note that the internals of the loop is left to the the user in the suggested replacement. This is where things become problematicRA picks up the suggested replacement
And now any code that was in the body of the if is gone
Reproducer
Using vscode + rust-analyzer with clippy suggestions
I tried this code:
pub fn loop_lint(x: Option<i32>) {
loop {
if let Some(_i) = x {
// many lines of work
} else {
break;
}
}
}
I expected to see this happen:
pub fn loop_lint(x: Option<i32>) {
while let Some(_i) = x {
// many lines of work
}
}
Instead, this happened:
pub fn loop_lint(x: Option<i32>) {
while let Some(_i) = x { .. }
}
Version
rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
Additional Labels
No response