-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveT-middleType: Probably requires verifiying typesType: Probably requires verifiying types
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.
alexheretic and Mizumaki
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveT-middleType: Probably requires verifiying typesType: Probably requires verifiying types