Skip to content

needless_continue false positive #14550

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

Open
asibahi opened this issue Apr 4, 2025 · 0 comments
Open

needless_continue false positive #14550

asibahi opened this issue Apr 4, 2025 · 0 comments
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

@asibahi
Copy link

asibahi commented Apr 4, 2025

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

@asibahi asibahi 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 Apr 4, 2025
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

No branches or pull requests

1 participant