@@ -3,7 +3,7 @@ use super::utils::make_iterator_snippet;
3
3
use clippy_utils:: diagnostics:: span_lint_and_then;
4
4
use clippy_utils:: msrvs:: { self , Msrv } ;
5
5
use clippy_utils:: visitors:: is_local_used;
6
- use clippy_utils:: { higher, path_to_local_id, peel_blocks_with_stmt} ;
6
+ use clippy_utils:: { higher, is_refutable , path_to_local_id, peel_blocks_with_stmt} ;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir:: def:: { DefKind , Res } ;
9
9
use rustc_hir:: { Expr , Pat , PatKind } ;
@@ -28,7 +28,7 @@ pub(super) fn check<'tcx>(
28
28
&& let PatKind :: Binding ( _, pat_hir_id, _, _) = pat. kind
29
29
&& path_to_local_id ( let_expr, pat_hir_id)
30
30
// Ensure the `if let` statement is for the `Some` variant of `Option` or the `Ok` variant of `Result`
31
- && let PatKind :: TupleStruct ( ref qpath, _ , _) = let_pat. kind
31
+ && let PatKind :: TupleStruct ( ref qpath, [ inner_pat ] , _) = let_pat. kind
32
32
&& let Res :: Def ( DefKind :: Ctor ( ..) , ctor_id) = cx. qpath_res ( qpath, let_pat. hir_id )
33
33
&& let Some ( variant_id) = cx. tcx . opt_parent ( ctor_id)
34
34
&& let some_ctor = cx. tcx . lang_items ( ) . option_some_variant ( ) == Some ( variant_id)
@@ -37,6 +37,7 @@ pub(super) fn check<'tcx>(
37
37
// Ensure expr in `if let` is not used afterwards
38
38
&& !is_local_used ( cx, if_then, pat_hir_id)
39
39
&& msrv. meets ( cx, msrvs:: ITER_FLATTEN )
40
+ && !is_refutable ( cx, inner_pat)
40
41
{
41
42
let if_let_type = if some_ctor { "Some" } else { "Ok" } ;
42
43
// Prepare the error message
0 commit comments