@@ -24,10 +24,14 @@ fn handle_expr(
24
24
span : Span ,
25
25
before_chars : Span ,
26
26
revert : bool ,
27
+ is_all : bool ,
27
28
) {
28
29
match expr. kind {
29
30
ExprKind :: MethodCall ( method, receiver, [ ] , _) => {
30
- if method. ident . name . as_str ( ) == "is_ascii"
31
+ // If we have `!is_ascii`, then only `.any()` should warn. And if the condition is
32
+ // `is_ascii`, then only `.all()` should warn.
33
+ if revert != is_all
34
+ && method. ident . name . as_str ( ) == "is_ascii"
31
35
&& path_to_local_id ( receiver, first_param)
32
36
&& let char_arg_ty = cx. typeck_results ( ) . expr_ty_adjusted ( receiver) . peel_refs ( )
33
37
&& * char_arg_ty. kind ( ) == ty:: Char
@@ -55,12 +59,23 @@ fn handle_expr(
55
59
&& let Some ( last_chain_binding_id) =
56
60
get_last_chain_binding_hir_id ( first_param, block. stmts )
57
61
{
58
- handle_expr ( cx, block_expr, last_chain_binding_id, span, before_chars, revert) ;
62
+ handle_expr (
63
+ cx,
64
+ block_expr,
65
+ last_chain_binding_id,
66
+ span,
67
+ before_chars,
68
+ revert,
69
+ is_all,
70
+ ) ;
59
71
}
60
72
} ,
61
- ExprKind :: Unary ( UnOp :: Not , expr) => handle_expr ( cx, expr, first_param, span, before_chars, !revert) ,
73
+ ExprKind :: Unary ( UnOp :: Not , expr) => handle_expr ( cx, expr, first_param, span, before_chars, !revert, is_all ) ,
62
74
ExprKind :: Call ( fn_path, [ arg] ) => {
63
- if let ExprKind :: Path ( path) = fn_path. kind
75
+ // If we have `!is_ascii`, then only `.any()` should warn. And if the condition is
76
+ // `is_ascii`, then only `.all()` should warn.
77
+ if revert != is_all
78
+ && let ExprKind :: Path ( path) = fn_path. kind
64
79
&& let Some ( fn_def_id) = cx. qpath_res ( & path, fn_path. hir_id ) . opt_def_id ( )
65
80
&& match_def_path ( cx, fn_def_id, & [ "core" , "char" , "methods" , "<impl char>" , "is_ascii" ] )
66
81
&& path_to_local_id ( peels_expr_ref ( arg) , first_param)
@@ -81,7 +96,7 @@ fn handle_expr(
81
96
}
82
97
}
83
98
84
- pub ( super ) fn check ( cx : & LateContext < ' _ > , call_expr : & Expr < ' _ > , recv : & Expr < ' _ > , closure_arg : & Expr < ' _ > ) {
99
+ pub ( super ) fn check ( cx : & LateContext < ' _ > , call_expr : & Expr < ' _ > , recv : & Expr < ' _ > , closure_arg : & Expr < ' _ > , is_all : bool ) {
85
100
if let ExprKind :: Closure ( & Closure { body, .. } ) = closure_arg. kind
86
101
&& let body = cx. tcx . hir ( ) . body ( body)
87
102
&& let Some ( first_param) = body. params . first ( )
@@ -103,6 +118,7 @@ pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>,
103
118
recv. span . with_hi ( call_expr. span . hi ( ) ) ,
104
119
recv. span . with_hi ( expr_start. hi ( ) ) ,
105
120
false ,
121
+ is_all,
106
122
) ;
107
123
}
108
124
}
0 commit comments