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 misses continue stmt inside let..else terminator #9356

Closed
yotamofek opened this issue Aug 20, 2022 · 0 comments · Fixed by #9496
Closed

never_loop misses continue stmt inside let..else terminator #9356

yotamofek opened this issue Aug 20, 2022 · 0 comments · Fixed by #9496
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

@yotamofek
Copy link
Contributor

Summary

Seems like the never_loop lint ignores any continue statements that are inside the else blocks in let..else statements. This produces a false positive.

Lint Name

never_loop

Reproducer

I tried this code:

#![feature(let_else)]

fn test(a: Option<usize>) {
    loop {
        // doesn't trigger lint:
        // if let Some(a) = a {
        let Some(a) = a else {
            continue;
        };

        break;
    }
}

I saw this happen:

error: this loop never actually loops
  --> src/lib.rs:6:5
   |
6  | /     loop {
7  | |         // doesn't trigger lint: if let Some(a) = a {
8  | |         let Some(a) = a else {
9  | |             continue;
...  |
14 | |         break;
15 | |     }
   | |_____^
   |
   = note: `#[deny(clippy::never_loop)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop

I expected to see this happen:
never_loop should not be triggered.

Version

rustc 1.65.0-nightly (86c6ebee8 2022-08-16)
binary: rustc
commit-hash: 86c6ebee8fa0a5ad1e18e375113b06bd2849b634
commit-date: 2022-08-16
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

Additional Labels

No response

@yotamofek yotamofek 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 Aug 20, 2022
@bors bors closed this as completed in ff65eec Sep 23, 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