@@ -26,6 +26,7 @@ mod implicit_clone;
2626mod inefficient_to_string;
2727mod inspect_for_each;
2828mod into_iter_on_ref;
29+ mod is_digit_ascii_radix;
2930mod iter_cloned_collect;
3031mod iter_count;
3132mod iter_next_slice;
@@ -2131,6 +2132,36 @@ declare_clippy_lint! {
21312132 "no-op use of `deref` or `deref_mut` method to `Option`."
21322133}
21332134
2135+ declare_clippy_lint ! {
2136+ /// ### What it does
2137+ /// Finds usages of [`char::is_digit`]
2138+ /// (https://doc.rust-lang.org/stable/std/primitive.char.html#method.is_digit) that
2139+ /// can be replaced with [`is_ascii_digit`]
2140+ /// (https://doc.rust-lang.org/stable/std/primitive.char.html#method.is_ascii_digit) or
2141+ /// [`is_ascii_hexdigit`]
2142+ /// (https://doc.rust-lang.org/stable/std/primitive.char.html#method.is_ascii_hexdigit).
2143+ ///
2144+ /// ### Why is this bad?
2145+ /// `is_digit(..)` is slower and requires specifying the radix.
2146+ ///
2147+ /// ### Example
2148+ /// ```rust
2149+ /// let c: char = '6';
2150+ /// c.is_digit(10);
2151+ /// c.is_digit(16);
2152+ /// ```
2153+ /// Use instead:
2154+ /// ```rust
2155+ /// let c: char = '6';
2156+ /// c.is_ascii_digit();
2157+ /// c.is_ascii_hexdigit();
2158+ /// ```
2159+ #[ clippy:: version = "1.61.0" ]
2160+ pub IS_DIGIT_ASCII_RADIX ,
2161+ style,
2162+ "use of `char::is_digit(..)` with literal radix of 10 or 16"
2163+ }
2164+
21342165pub struct Methods {
21352166 avoid_breaking_exported_api : bool ,
21362167 msrv : Option < RustcVersion > ,
@@ -2219,6 +2250,7 @@ impl_lint_pass!(Methods => [
22192250 UNNECESSARY_JOIN ,
22202251 ERR_EXPECT ,
22212252 NEEDLESS_OPTION_AS_DEREF ,
2253+ IS_DIGIT_ASCII_RADIX ,
22222254] ) ;
22232255
22242256/// Extracts a method call name, args, and `Span` of the method name.
@@ -2516,6 +2548,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
25162548 } ,
25172549 ( "get_or_insert_with" , [ arg] ) => unnecessary_lazy_eval:: check ( cx, expr, recv, arg, "get_or_insert" ) ,
25182550 ( "is_file" , [ ] ) => filetype_is_file:: check ( cx, expr, recv) ,
2551+ ( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, msrv) ,
25192552 ( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
25202553 ( "is_some" , [ ] ) => check_is_some_is_none ( cx, expr, recv, true ) ,
25212554 ( "join" , [ join_arg] ) => {
0 commit comments