Skip to content

manual_ok_err: don't lint subpatterns #14661

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

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/manual_ok_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn is_variant_or_wildcard(cx: &LateContext<'_>, pat: &Pat<'_>, can_be_wild: bool
/// contains `Err(IDENT)`, `None` otherwise.
fn is_ok_or_err<'hir>(cx: &LateContext<'_>, pat: &Pat<'hir>) -> Option<(bool, &'hir Ident)> {
if let PatKind::TupleStruct(qpath, [arg], _) = &pat.kind
&& let PatKind::Binding(BindingMode::NONE, _, ident, _) = &arg.kind
&& let PatKind::Binding(BindingMode::NONE, _, ident, None) = &arg.kind
&& let res = cx.qpath_res(qpath, pat.hir_id)
&& let Res::Def(DefKind::Ctor(..), id) = res
&& let id @ Some(_) = cx.tcx.opt_parent(id)
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/manual_ok_err.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ fn no_lint() {
Ok(3) => None,
Ok(v) => Some(v),
};

let _ = match funcall() {
Ok(v @ 1..) => Some(v),
_ => None,
};
}

const fn cf(x: Result<u32, &'static str>) -> Option<u32> {
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/manual_ok_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ fn no_lint() {
Ok(3) => None,
Ok(v) => Some(v),
};

let _ = match funcall() {
Ok(v @ 1..) => Some(v),
_ => None,
};
}

const fn cf(x: Result<u32, &'static str>) -> Option<u32> {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_ok_err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ LL | | };
| |_____^ help: replace with: `(-S).ok()`

error: manual implementation of `ok`
--> tests/ui/manual_ok_err.rs:132:12
--> tests/ui/manual_ok_err.rs:137:12
|
LL | } else if let Ok(n) = "1".parse::<u8>() {
| ____________^
Expand Down