Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive in clippy::while_let_on_iterator #6491

Closed
bertptrs opened this issue Dec 21, 2020 · 2 comments · Fixed by #6966
Closed

False positive in clippy::while_let_on_iterator #6491

bertptrs opened this issue Dec 21, 2020 · 2 comments · Fixed by #6966
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-MIR Type: This lint will require working with the MIR

Comments

@bertptrs
Copy link

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

@bertptrs bertptrs added the C-bug Category: Clippy is not doing the correct thing label Dec 21, 2020
@giraffate giraffate added I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Dec 21, 2020
@giraffate
Copy link
Contributor

This is similar to #5844.

@ThibsG
Copy link
Contributor

ThibsG commented Jan 5, 2021

@rustbot label +T-MIR

@rustbot rustbot added the T-MIR Type: This lint will require working with the MIR label Jan 5, 2021
@bors bors closed this as completed in 90fb7c4 May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-MIR Type: This lint will require working with the MIR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants