diff options
| author | bors <bors@rust-lang.org> | 2022-08-18 18:13:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-18 18:13:39 +0000 |
| commit | eeaaba3713d6590459f4516a783fbf76b3e59c2f (patch) | |
| tree | d6222f5cf6b9ea031825ecc08f9d2fe486393e41 | |
| parent | c419d0a8b538de6000226cc54a2f18a03bbd31d6 (diff) | |
| parent | e87a5a1cc5e799b929abf27a03a6535a88698ce6 (diff) | |
| download | rust-eeaaba3713d6590459f4516a783fbf76b3e59c2f.tar.gz rust-eeaaba3713d6590459f4516a783fbf76b3e59c2f.zip | |
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
| -rw-r--r-- | clippy_lints/src/question_mark.rs | 2 | ||||
| -rw-r--r-- | tests/ui/question_mark.fixed | 15 | ||||
| -rw-r--r-- | tests/ui/question_mark.rs | 15 |
3 files changed, 31 insertions, 1 deletions
diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 964a057f00d..b432ccb1ee3 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -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 !is_else_clause(cx.tcx, expr); 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 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)) diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed index c4c9c821433..57f23bd1916 100644 --- a/tests/ui/question_mark.fixed +++ b/tests/ui/question_mark.fixed @@ -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() {} diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index cdbc7b1606f..436f027c215 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -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() {} |
