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

Bad while_let_on_iterator suggestion when pattern is refutable #3780

Closed
ghost opened this issue Feb 18, 2019 · 0 comments · Fixed by #5559
Closed

Bad while_let_on_iterator suggestion when pattern is refutable #3780

ghost opened this issue Feb 18, 2019 · 0 comments · Fixed by #5559
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@ghost
Copy link

ghost commented Feb 18, 2019

Here is an example:

fn main() {
    let v = vec![1, 2, 3];
    
    {
        let mut it = v.windows(2);
        while let Some([x, y]) = it.next() {
            println!("x: {}", x);
            println!("y: {}", y);
        }
    }
    /*
    warning: this loop could be written as a `for` loop
     --> src/main.rs:6:34
      |
    6 |         while let Some([x, y]) = it.next() {
      |                                  ^^^^^^^^^ help: try: `for [x, y] in it { .. }`
      |
      = note: #[warn(clippy::while_let_on_iterator)] on by default
    */
    
    // The Clippy suggestion fails to compile
    /*
    {
        let mut it = v.windows(2);
        for [x, y] in it {
            println!("x: {}", x);
            println!("y: {}", y);
        }
    }
    */
}

Playground

@phansch phansch added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Feb 18, 2019
@bors bors closed this as completed in 60538d6 May 2, 2020
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
1 participant