-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedT-MIRType: This lint will require working with the MIRType: This lint will require working with the MIR
Description
I tried this code: (simplified, the original made more sense)
fn main() {
let mut it = 1..40;
while let Some(n) = it.next() {
while let Some(m) = it.next() {
if m % 10 == 0 {
break;
}
println!("doing something with m: {}", m);
}
println!("n still is {}", n);
}
}I expected to see this happen: this passes cargo clippy just fine.
Instead, this happened: it suggests an invalid improvement:
warning: this loop could be written as a `for` loop
--> src/main.rs:5:29
|
5 | while let Some(m) = it.next() {
| ^^^^^^^^^ help: try: `for m in it { .. }`
|
= note: `#[warn(clippy::while_let_on_iterator)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator
warning: 1 warning emitted
This moves out of it, which isn't allowed because it's needed in the next loop iteration.
Meta
cargo clippy -V: clippy 0.0.212 (891e1a8 2020-04-18)rustc -Vv:rustc 1.48.0 binary: rustc commit-hash: unknown commit-date: unknown host: x86_64-unknown-linux-gnu release: 1.48.0 LLVM version: 11.0- Installed from https://archlinux.org/packages/extra/x86_64/rust/
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedT-MIRType: This lint will require working with the MIRType: This lint will require working with the MIR