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
This commit is contained in:
commit
eeaaba3713
3 changed files with 31 additions and 1 deletions
|
@ -123,7 +123,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
|
||||||
if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else }) = higher::IfLet::hir(cx, expr);
|
if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else }) = higher::IfLet::hir(cx, expr);
|
||||||
if !is_else_clause(cx.tcx, expr);
|
if !is_else_clause(cx.tcx, expr);
|
||||||
if let PatKind::TupleStruct(ref path1, [field], None) = let_pat.kind;
|
if let PatKind::TupleStruct(ref path1, [field], None) = let_pat.kind;
|
||||||
if let PatKind::Binding(annot, bind_id, ident, _) = field.kind;
|
if let PatKind::Binding(annot, bind_id, ident, None) = field.kind;
|
||||||
let caller_ty = cx.typeck_results().expr_ty(let_expr);
|
let caller_ty = cx.typeck_results().expr_ty(let_expr);
|
||||||
let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else);
|
let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else);
|
||||||
if (is_early_return(sym::Option, cx, &if_block) && path_to_local_id(peel_blocks(if_then), bind_id))
|
if (is_early_return(sym::Option, cx, &if_block) && path_to_local_id(peel_blocks(if_then), bind_id))
|
||||||
|
|
|
@ -207,4 +207,19 @@ fn option_map() -> Option<bool> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct PatternedError {
|
||||||
|
flag: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
// No warning
|
||||||
|
fn pattern() -> Result<(), PatternedError> {
|
||||||
|
let res = Ok(());
|
||||||
|
|
||||||
|
if let Err(err @ PatternedError { flag: true }) = res {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -243,4 +243,19 @@ fn option_map() -> Option<bool> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct PatternedError {
|
||||||
|
flag: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
// No warning
|
||||||
|
fn pattern() -> Result<(), PatternedError> {
|
||||||
|
let res = Ok(());
|
||||||
|
|
||||||
|
if let Err(err @ PatternedError { flag: true }) = res {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue