mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Do not ignore statements before a break when simplifying loop
The previous tests ignored statements in a block and only looked at the final expression to determine if the block was made of a single `break`.
This commit is contained in:
@@ -253,3 +253,24 @@ fn let_assign() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn issue16378() {
|
||||
// This does not lint today because of the extra statement(s)
|
||||
// before the `break`.
|
||||
// TODO: When the `break` statement/expr in the `let`/`else` is the
|
||||
// only way to leave the loop, the lint could trigger and move
|
||||
// the statements preceeding the `break` after the loop, as in:
|
||||
// ```rust
|
||||
// while let Some(x) = std::hint::black_box(None::<i32>) {
|
||||
// println!("x = {x}");
|
||||
// }
|
||||
// println!("fail");
|
||||
// ```
|
||||
loop {
|
||||
let Some(x) = std::hint::black_box(None::<i32>) else {
|
||||
println!("fail");
|
||||
break;
|
||||
};
|
||||
println!("x = {x}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user