Skip to content

Commit eeaaba3

Browse files
committed
Auto merge of #9348 - lukaslueg:issue9347, r=Alexendoo
Don't lint on match pattern-binding in ´question_mark` Fixes #9347 Technically it is possible to have a blank match-pattern that does nothing, and we fail to lint. But it's easier to be safe than sorry here. changelog: [`question_mark`]: don't lint `if let`s with subpatterns
2 parents c419d0a + e87a5a1 commit eeaaba3

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

clippy_lints/src/question_mark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
123123
if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else }) = higher::IfLet::hir(cx, expr);
124124
if !is_else_clause(cx.tcx, expr);
125125
if let PatKind::TupleStruct(ref path1, [field], None) = let_pat.kind;
126-
if let PatKind::Binding(annot, bind_id, ident, _) = field.kind;
126+
if let PatKind::Binding(annot, bind_id, ident, None) = field.kind;
127127
let caller_ty = cx.typeck_results().expr_ty(let_expr);
128128
let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else);
129129
if (is_early_return(sym::Option, cx, &if_block) && path_to_local_id(peel_blocks(if_then), bind_id))

tests/ui/question_mark.fixed

+15
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,19 @@ fn option_map() -> Option<bool> {
207207
}
208208
}
209209

210+
pub struct PatternedError {
211+
flag: bool,
212+
}
213+
214+
// No warning
215+
fn pattern() -> Result<(), PatternedError> {
216+
let res = Ok(());
217+
218+
if let Err(err @ PatternedError { flag: true }) = res {
219+
return Err(err);
220+
}
221+
222+
res
223+
}
224+
210225
fn main() {}

tests/ui/question_mark.rs

+15
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,19 @@ fn option_map() -> Option<bool> {
243243
}
244244
}
245245

246+
pub struct PatternedError {
247+
flag: bool,
248+
}
249+
250+
// No warning
251+
fn pattern() -> Result<(), PatternedError> {
252+
let res = Ok(());
253+
254+
if let Err(err @ PatternedError { flag: true }) = res {
255+
return Err(err);
256+
}
257+
258+
res
259+
}
260+
246261
fn main() {}

0 commit comments

Comments
 (0)