Skip to content

needless_continue false positive #14550

Open
@asibahi

Description

@asibahi

Summary

I have been directed to open this as an issue.

I got a false positive for this lint, including this (honestly absurd) loop match construct.

let mut counter = 2;
let buf = loop {
    match AGENT.get(link.as_str()).call() {
        Ok(mut res) => break res.body_mut().read_to_vec()?,
        Err(ureq::Error::Io(err))
            if counter > 0 && err.kind() == std::io::ErrorKind::ConnectionReset =>
        {
            std::thread::sleep(std::time::Duration::from_millis(200));
            counter -= 1;
            continue; // <-- clippy pedantic: this continue expression is redundant
        },
        err => err?,
    };
};

Removing the continue gives me a compiler error.

error[E0308]: `match` arms have incompatible types
   --> mimiron/src/deck_image.rs:484:16
    |
475 | /     match AGENT.get(link.as_str()).call() {
476 | |         Ok(mut res) => break res.body_mut().read_to_vec()?,
477 | |         Err(ureq::Error::Io(err))
478 | |             if counter > 0 && err.kind() == std::io::ErrorKind::ConnectionReset =>
...   |
481 | |             counter -= 1;
    | |             ------------- this is found to be of type `()`
...   |
484 | |         err => err?,
    | |                ^^^^ expected `()`, found `Response<Body>`
485 | |     };
    | |_____- `match` arms have incompatible types
    |
    = note: expected unit type `()`
                  found struct `ureq::http::Response<ureq::Body>`

This is easily worked around by wrapping the err? expression in braces and a semicolon. But it is why I added the continue in the first place.

Lint Name

needless_continue

Reproducer

Shown above.

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: aarch64-apple-darwin
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

No response

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