- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing