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

never_loop false positive on unconditional break to internal labeled block #9831

Closed
cwfitzgerald opened this issue Nov 11, 2022 · 0 comments · Fixed by #9837
Closed

never_loop false positive on unconditional break to internal labeled block #9831

cwfitzgerald opened this issue Nov 11, 2022 · 0 comments · Fixed by #9837
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

Comments

@cwfitzgerald
Copy link

cwfitzgerald commented Nov 11, 2022

Summary

Having an internal labeled block which is always broken to causes a false positive on never_loop.

Lint Name

never_loop

Reproducer

I tried this code: (playground)

fn thing(iter: impl Iterator) {
    for _ in iter {
        'b: {
            // error goes away if we just have the block's value be ().
            break 'b;
        }
    }
}

I saw this error:

error: this loop never actually loops
 --> src/lib.rs:2:5
  |
2 | /     for _ in iter {
3 | |         'b: {
4 | |             break 'b;
5 | |         }
6 | |     }
  | |_____^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
  = note: `#[deny(clippy::never_loop)]` on by default
help: if you need the first element of the iterator, try writing
  |
2 |     if let Some(_) = iter.next() {
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Version

rustc 1.67.0-nightly (e75aab045 2022-11-09)
binary: rustc
commit-hash: e75aab045fc476f176a58c408f6b06f0e275c6e1
commit-date: 2022-11-09
host: aarch64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4

Additional Labels

No response

@cwfitzgerald cwfitzgerald added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Nov 11, 2022
kartva added a commit to kartva/rust-clippy that referenced this issue Nov 12, 2022
on unconditional break to internal labeled block

ref rust-lang#9831
kartva added a commit to kartva/rust-clippy that referenced this issue Nov 12, 2022
on unconditional break to internal labeled block

ref rust-lang#9831
@bors bors closed this as completed in a599527 Nov 13, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant