Skip to content

Commit f08b47f

Browse files
Fix incorrect suggestion for manual_unwrap_or_default
1 parent 29cc5c6 commit f08b47f

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

clippy_lints/src/manual_unwrap_or_default.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ fn get_some<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<HirId> {
6060
&& (cx.tcx.lang_items().get(LangItem::OptionSome) == Some(def_id)
6161
|| cx.tcx.lang_items().get(LangItem::ResultOk) == Some(def_id))
6262
{
63+
if let PatKind::Tuple(elements, dotdot) = pat.kind
64+
&& (elements.len() > 1 || dotdot.as_opt_usize().is_some())
65+
{
66+
return None;
67+
}
6368
let mut bindings = Vec::new();
6469
pat.each_binding(|_, id, _, _| bindings.push(id));
6570
if let &[id] = bindings.as_slice() {

tests/ui/manual_unwrap_or_default.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ fn issue_12569() {
7878
0
7979
};
8080
}
81+
82+
// Should not warn!
83+
fn issue_12928() {
84+
let x = Some((1, 2));
85+
let y = if let Some((a, _)) = x { a } else { 0 };
86+
let y = if let Some((a, ..)) = x { a } else { 0 };
87+
}

tests/ui/manual_unwrap_or_default.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,10 @@ fn issue_12569() {
111111
0
112112
};
113113
}
114+
115+
// Should not warn!
116+
fn issue_12928() {
117+
let x = Some((1, 2));
118+
let y = if let Some((a, _)) = x { a } else { 0 };
119+
let y = if let Some((a, ..)) = x { a } else { 0 };
120+
}

0 commit comments

Comments
 (0)