Skip to content

Commit 083ea7e

Browse files
authored
manual_ok_err: don't lint subpatterns (#14661)
Fixes rust-lang/rust-clippy#14660 changelog: none
2 parents cc00c77 + 8843067 commit 083ea7e

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

clippy_lints/src/matches/manual_ok_err.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn is_variant_or_wildcard(cx: &LateContext<'_>, pat: &Pat<'_>, can_be_wild: bool
8585
/// contains `Err(IDENT)`, `None` otherwise.
8686
fn is_ok_or_err<'hir>(cx: &LateContext<'_>, pat: &Pat<'hir>) -> Option<(bool, &'hir Ident)> {
8787
if let PatKind::TupleStruct(qpath, [arg], _) = &pat.kind
88-
&& let PatKind::Binding(BindingMode::NONE, _, ident, _) = &arg.kind
88+
&& let PatKind::Binding(BindingMode::NONE, _, ident, None) = &arg.kind
8989
&& let res = cx.qpath_res(qpath, pat.hir_id)
9090
&& let Res::Def(DefKind::Ctor(..), id) = res
9191
&& let id @ Some(_) = cx.tcx.opt_parent(id)

tests/ui/manual_ok_err.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ fn no_lint() {
8080
Ok(3) => None,
8181
Ok(v) => Some(v),
8282
};
83+
84+
let _ = match funcall() {
85+
Ok(v @ 1..) => Some(v),
86+
_ => None,
87+
};
8388
}
8489

8590
const fn cf(x: Result<u32, &'static str>) -> Option<u32> {

tests/ui/manual_ok_err.rs

+5
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ fn no_lint() {
116116
Ok(3) => None,
117117
Ok(v) => Some(v),
118118
};
119+
120+
let _ = match funcall() {
121+
Ok(v @ 1..) => Some(v),
122+
_ => None,
123+
};
119124
}
120125

121126
const fn cf(x: Result<u32, &'static str>) -> Option<u32> {

tests/ui/manual_ok_err.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ LL | | };
9494
| |_____^ help: replace with: `(-S).ok()`
9595

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

0 commit comments

Comments
 (0)