Open
Description
fn main() {
let mut lines = "foo".lines().peekable();
// Gather remaining non-empty lines into a comment field.
let mut comment = String::new();
loop {
if let Some(line) = lines.peek() {
if line.is_empty() {
break;
} else {
comment += line;
}
} else {
break;
}
// Consume
lines.next();
}
}
warning: this loop could be written as a `while let` loop
--> src/main.rs:5:5
|
5 | / loop {
6 | | if let Some(line) = lines.peek() {
7 | | if line.is_empty() {
8 | | break;
... |
16 | | lines.next();
17 | | }
| |_____^
|
= note: #[warn(while_let_loop)] on by default
help: try
| while let Some(line) = lines.peek() { .. }
This can't be trivially transformed into while let
, since lines.next()
is called unconditionally outside of the if let
statement.