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

Incorrect infinite loop detection when using breakpoint labels and continue #13511

Closed
PartyWumpus opened this issue Oct 6, 2024 · 0 comments · Fixed by #13512
Closed

Incorrect infinite loop detection when using breakpoint labels and continue #13511

PartyWumpus opened this issue Oct 6, 2024 · 0 comments · Fixed by #13512
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

@PartyWumpus
Copy link

PartyWumpus commented Oct 6, 2024

Summary

If you have an outer loop that does terminate, and an inner loop that terminates by continueing into the outer loop, clippy::infinite_loop will mark the inner loop as an infinite loop.

Lint Name

clippy::infinite_loop

Reproducer

I tried this code:

fn main() {
    let mut count = 0;
    'outer: loop {
        if count != 0 {
            break;
        }

        'inner: loop {
            count += 1;
            continue 'outer;
        }
    }
    println!("This line is reached fine!");
}

I saw this happen:

warning: infinite loop detected
  --> src/main.rs:8:9
   |
8  | /         'inner: loop {
9  | |             count += 1;
10 | |             continue 'outer;
11 | |         }
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-cli
ppy/master/index.html#infinite_loop
   = note: `-W clippy::infinite-loop` implied by `-W clippy::restriction`
   = help: to override `-W clippy::restriction` add `#[allow(clippy::infinite
_loop)]`
help: if this is intentional, consider specifying `!` as function return
   |
1  | fn main() -> ! {
   |           ++++

It also triggered clippy::never-loop for the same loop which is silly.

I expected to see this happen:
No infinite loop warning triggered.

Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Additional Labels

No response

@PartyWumpus PartyWumpus 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 Oct 6, 2024
@bors bors closed this as completed in d9c8d97 Oct 8, 2024
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