Skip to content

clippy::while_let_loop incorectly scope variable #7913

@xNxExOx

Description

@xNxExOx

Lint name: clippy::while_let_loop

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6e0c751f49cce697e1f06bcc1fed429e

I simplify it by changing instances to only 5, and "work" to just short sleep to run better on playground, but I have 32 core CPU, so using more than one core at time is important for me.

loop {
// lock mutex to obtain next thing to process, and unlock it before processing it
    let seed = if let Some(seed) = seeds.lock().unwrap().pop_front() {
        seed
    } else {
        break
    };
    // do something
}

I expected to see this happen: no lint, or suggestion that does not break the code

Instead, this happened: suggested code is running one thread at time, instead of many, which is significant performance impact.

Meta

Rust version (rustc -Vv):

rustc 1.58.0-nightly (29b124802 2021-10-25)
binary: rustc
commit-hash: 29b1248025b19bd132c8047fc710ea9314b9b76b
commit-date: 2021-10-25
host: x86_64-pc-windows-msvc
release: 1.58.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions