Skip to content

false positive on while_immutable_condition #4648

Closed
@kpp

Description

@kpp

Code:

pub fn skip_while<St, F, Fut>(stream: St, f: F) -> impl Stream<Item = St::Item>
where
    St: Stream,
    F: FnMut(&St::Item) -> Fut,
    Fut: Future<Output = bool>,
{
    let stream = Box::pin(stream);
    let should_skip = true;
    crate::stream::unfold(
        (stream, f, should_skip),
        |(mut stream, mut f, should_skip)| async move {
            while should_skip {
                if let Some(item) = next(&mut stream).await {
                    if f(&item).await {
                        continue;
                    } else {
                        return Some((item, (stream, f, /* should_skip */ false)));
                    }
                } else {
                    return None;
                }
            }
            if let Some(item) = next(&mut stream).await {
                Some((item, (stream, f, /* should_skip */ false)))
            } else {
                None
            }
        },
    )
}

Error:

error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
   --> src/stream.rs:717:19
    |
717 |             while should_skip {
    |                   ^^^^^^^^^^^
    |

https://github.com/kpp/futures-async-combinators/blob/d8da69c9f3b4587a99ddf1e0e5545bcff81cf57c/src/stream.rs#L718

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-correctnessLint: Belongs in the correctness lint groupL-styleLint: Belongs in the style lint groupgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions