@@ -47,12 +47,9 @@ pub(super) fn check(cx: &LateContext<'_>, arms: &[Arm<'_>]) {
47
47
arm. guard ,
48
48
& mut app,
49
49
) ;
50
-
51
- continue ;
52
50
}
53
-
54
51
// `Some(x) if let Some(2) = x`
55
- if let Guard :: IfLet ( let_expr) = guard
52
+ else if let Guard :: IfLet ( let_expr) = guard
56
53
&& let pat = let_expr. pat
57
54
&& let Some ( ( pat_binding, field_name) ) = get_pat_binding ( cx, let_expr. init , outer_arm)
58
55
{
@@ -66,16 +63,20 @@ pub(super) fn check(cx: &LateContext<'_>, arms: &[Arm<'_>]) {
66
63
None ,
67
64
& mut app,
68
65
) ;
69
-
70
- continue ;
71
66
}
72
-
73
67
// `Some(x) if x == Some(2)`
74
- if let Guard :: If ( if_expr) = guard
68
+ else if let Guard :: If ( if_expr) = guard
75
69
&& let ExprKind :: Binary ( bin_op, local, pat) = if_expr. kind
76
70
&& matches ! ( bin_op. node, BinOpKind :: Eq )
77
71
&& let Some ( ( pat_binding, field_name) ) = get_pat_binding ( cx, local, outer_arm)
78
72
&& expr_can_be_pat ( cx, pat)
73
+ // Ensure they have the same type. If they don't, we'd need deref coercion which isn't
74
+ // possible (currently) in a pattern. In some cases, you can use something like
75
+ // `as_deref` or similar but in general, we shouldn't lint this as it'd create an
76
+ // extraordinary amount of FPs.
77
+ //
78
+ // This isn't necessary in the other two checks, as they must be a pattern already.
79
+ && cx. typeck_results ( ) . expr_ty ( local) == cx. typeck_results ( ) . expr_ty ( pat)
79
80
{
80
81
emit_redundant_guard (
81
82
cx,
@@ -87,8 +88,6 @@ pub(super) fn check(cx: &LateContext<'_>, arms: &[Arm<'_>]) {
87
88
None ,
88
89
& mut app,
89
90
) ;
90
-
91
- continue ;
92
91
}
93
92
}
94
93
}
@@ -217,17 +216,13 @@ fn expr_can_be_pat(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
217
216
218
217
true
219
218
} ,
220
- ExprKind :: Struct ( _, fields, rest ) => {
219
+ ExprKind :: Struct ( _, fields, None ) => {
221
220
for field in fields {
222
221
if !helper ( cx, field. expr ) {
223
222
return ControlFlow :: Break ( ( ) ) ;
224
223
}
225
224
}
226
225
227
- if rest. is_some ( ) {
228
- return ControlFlow :: Break ( ( ) ) ;
229
- }
230
-
231
226
true
232
227
} ,
233
228
ExprKind :: Path ( qpath) => {
0 commit comments