Skip to content

Incorrect behaviour change suggestion for manual_ok_err #14660

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
jtroo opened this issue Apr 20, 2025 · 0 comments · Fixed by #14661
Closed

Incorrect behaviour change suggestion for manual_ok_err #14660

jtroo opened this issue Apr 20, 2025 · 0 comments · Fixed by #14661
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@jtroo
Copy link

jtroo commented Apr 20, 2025

Summary

This code snippet gets incorrectly caught by the manual_ok_err check when it is incorrect to apply it. The expected behaviour is that the clippy lint does not fire in this function.

fn parse_non_zero_u16(expr: &SExpr, s: &ParserState, label: &str) -> Result<u16> {
    expr.atom(s.vars())
        .map(str::parse::<u16>)
        .and_then(|u| match u {
            Ok(u @ 1..) => Some(u),
            _ => None,
        })
        .ok_or_else(|| anyhow_expr!(expr, "{label} must be 1-65535"))
}

Clippy suggests:

2068 |           .and_then(|u| match u {
     |  _______________________^
2069 | |             Ok(u @ 1..) => Some(u),
2070 | |             _ => None,
2071 | |         })
     | |_________^ help: replace with: `u.ok()`

I reviewed issue #14533 and #14239 as well which looked related to manual_ok_err but they don't immediately seem to be the same issue to me.

Reproducer

I tried this code:

        match u {
            Ok(u @ 1..) => Some(u),
            _ => None,
        }

I expected to see this happen:

No clippy lint fires.

Instead, this happened:

Clippy lint fires and suggests a behaviour change.

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-pc-windows-msvc
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

No response

@jtroo jtroo added the C-bug Category: Clippy is not doing the correct thing label Apr 20, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 21, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant