@@ -29,7 +29,7 @@ pub(super) fn check<'tcx>(
29
29
&& let PatKind :: Binding ( _, pat_hir_id, _, _) = pat. kind
30
30
&& path_to_local_id ( let_expr, pat_hir_id)
31
31
// Ensure the `if let` statement is for the `Some` variant of `Option` or the `Ok` variant of `Result`
32
- && let PatKind :: TupleStruct ( ref qpath, _ , _) = let_pat. kind
32
+ && let PatKind :: TupleStruct ( ref qpath, let_pats , _) = let_pat. kind
33
33
&& let Res :: Def ( DefKind :: Ctor ( ..) , ctor_id) = cx. qpath_res ( qpath, let_pat. hir_id )
34
34
&& let Some ( variant_id) = cx. tcx . opt_parent ( ctor_id)
35
35
&& let some_ctor = cx. tcx . lang_items ( ) . option_some_variant ( ) == Some ( variant_id)
@@ -57,15 +57,27 @@ pub(super) fn check<'tcx>(
57
57
58
58
let help_msg = "try `.flatten()` and remove the `if let` statement in the for loop" ;
59
59
60
- let body_snip =
60
+ let pat_snippet = if let_pats. is_empty ( ) {
61
+ "_" . to_string ( )
62
+ } else {
63
+ snippet_with_applicability (
64
+ cx,
65
+ let_pats. first ( ) . unwrap ( ) . span . source_callsite ( ) ,
66
+ "_" ,
67
+ & mut applicability,
68
+ )
69
+ . to_string ( )
70
+ } ;
71
+ let body_snippet =
61
72
snippet_with_applicability ( cx, if_then. span . source_callsite ( ) , "[body]" , & mut applicability) . to_string ( ) ;
62
73
let suggestions = vec ! [
63
74
// flatten the iterator
64
75
( arg. span, format!( "{arg_snippet}{copied}.flatten()" ) ) ,
76
+ ( pat. span, pat_snippet) ,
65
77
// remove the `if let` statement
66
78
(
67
79
body. span,
68
- reindent_multiline( & body_snip , true , indent_of( cx, body. span) ) ,
80
+ reindent_multiline( & body_snippet , true , indent_of( cx, body. span) ) ,
69
81
) ,
70
82
] ;
71
83
0 commit comments