Skip to content

never_loop false positive with struct expressions #9001

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

Closed
andylizi opened this issue Jun 15, 2022 · 0 comments · Fixed by #9002
Closed

never_loop false positive with struct expressions #9001

andylizi opened this issue Jun 15, 2022 · 0 comments · Fixed by #9002
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

@andylizi
Copy link
Contributor

andylizi commented Jun 15, 2022

Summary

never_loop does not pick up continue in struct expression fields.

Lint Name

never_loop

Reproducer

I tried this code:

struct Foo {
    f: u8
}

fn my_func1() -> Foo {
    loop {
        break Foo {
            f: if 1 + 1 == 3 {
                0
            } else {
                continue;
            }
        }
    }
}

(playground)

I saw this happen:

error: this loop never actually loops
  --> src/lib.rs:6:5
   |
6  | /     loop {
7  | |         break Foo {
8  | |             f: if 1 + 1 == 3 { 0 } else { continue; }
9  | |         }
10 | |     }
   | |_____^
   |
   = note: `#[deny(clippy::never_loop)]` on by default

I expected no error, since it will loop forever.

Version

rustc 1.63.0-nightly (ca122c7eb 2022-06-13)
binary: rustc
commit-hash: ca122c7ebb3ab50149c9d3d24ddb59c252b32272
commit-date: 2022-06-13
host: x86_64-pc-windows-msvc
release: 1.63.0-nightly
LLVM version: 14.0.5
@andylizi andylizi 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 Jun 15, 2022
@bors bors closed this as completed in 71f2de9 Jun 15, 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