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

clippy::never_loop has false positive with break from labeled blocks #10304

Closed
Calvin304 opened this issue Feb 7, 2023 · 0 comments · Fixed by #10311
Closed

clippy::never_loop has false positive with break from labeled blocks #10304

Calvin304 opened this issue Feb 7, 2023 · 0 comments · Fixed by #10311
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

@Calvin304
Copy link

Summary

clippy::never_loop is triggering on a loop with a break to a labeled block. i couldnt seem to get a false positive for nested loops with break statements, so its probably a bug specifically with rfc#2046 (stabalized in 1.65).

Lint Name

never_loop

Reproducer

I tried this code:

fn main() {
    for _ in 0..10 {
        'block: {
            break 'block;
            return;
        }
        println!("looped");
    }
}

playground link

I saw this happen:

error: this loop never actually loops
  --> src/main.rs:4:5
   |
4  | /     for _ in 0..10 {
5  | |         'block: {
6  | |             break 'block;
7  | |             return;
8  | |         }
9  | |         println!("looped");
10 | |     }
   | |_____^

This is in spite of this loop looping 10 times when run.

Version

rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6

Additional Labels

No response

@Calvin304 Calvin304 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 Feb 7, 2023
@bors bors closed this as completed in a182a67 Feb 14, 2023
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