@@ -26,6 +26,7 @@ mod implicit_clone;
26
26
mod inefficient_to_string;
27
27
mod inspect_for_each;
28
28
mod into_iter_on_ref;
29
+ mod is_digit_ascii_radix;
29
30
mod iter_cloned_collect;
30
31
mod iter_count;
31
32
mod iter_next_slice;
@@ -2106,6 +2107,36 @@ declare_clippy_lint! {
2106
2107
"using `.collect::<Vec<String>>().join(\" \" )` on an iterator"
2107
2108
}
2108
2109
2110
+ declare_clippy_lint ! {
2111
+ /// ### What it does
2112
+ /// Finds usages of [`char::is_digit`]
2113
+ /// (https://doc.rust-lang.org/stable/std/primitive.char.html#method.is_digit) that
2114
+ /// can be replaced with [`is_ascii_digit`]
2115
+ /// (https://doc.rust-lang.org/stable/std/primitive.char.html#method.is_ascii_digit) or
2116
+ /// [`is_ascii_hexdigit`]
2117
+ /// (https://doc.rust-lang.org/stable/std/primitive.char.html#method.is_ascii_hexdigit).
2118
+ ///
2119
+ /// ### Why is this bad?
2120
+ /// `is_digit(..)` is slower and requires specifying the radix.
2121
+ ///
2122
+ /// ### Example
2123
+ /// ```rust
2124
+ /// let c: char = '6';
2125
+ /// c.is_digit(10);
2126
+ /// c.is_digit(16);
2127
+ /// ```
2128
+ /// Use instead:
2129
+ /// ```rust
2130
+ /// let c: char = '6';
2131
+ /// c.is_ascii_digit();
2132
+ /// c.is_ascii_hexdigit();
2133
+ /// ```
2134
+ #[ clippy:: version = "1.61.0" ]
2135
+ pub IS_DIGIT_ASCII_RADIX ,
2136
+ style,
2137
+ "use of `char::is_digit(..)` with literal radix of 10 or 16"
2138
+ }
2139
+
2109
2140
pub struct Methods {
2110
2141
avoid_breaking_exported_api : bool ,
2111
2142
msrv : Option < RustcVersion > ,
@@ -2193,6 +2224,7 @@ impl_lint_pass!(Methods => [
2193
2224
UNNECESSARY_TO_OWNED ,
2194
2225
UNNECESSARY_JOIN ,
2195
2226
ERR_EXPECT ,
2227
+ IS_DIGIT_ASCII_RADIX ,
2196
2228
] ) ;
2197
2229
2198
2230
/// Extracts a method call name, args, and `Span` of the method name.
@@ -2488,6 +2520,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
2488
2520
} ,
2489
2521
( "get_or_insert_with" , [ arg] ) => unnecessary_lazy_eval:: check ( cx, expr, recv, arg, "get_or_insert" ) ,
2490
2522
( "is_file" , [ ] ) => filetype_is_file:: check ( cx, expr, recv) ,
2523
+ ( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, msrv) ,
2491
2524
( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
2492
2525
( "is_some" , [ ] ) => check_is_some_is_none ( cx, expr, recv, true ) ,
2493
2526
( "join" , [ join_arg] ) => {
0 commit comments