Skip to content

Commit d020b6f

Browse files
committed
MSRV and more specific message
1 parent 44c084b commit d020b6f

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

clippy_lints/src/methods/is_digit_ascii_radix.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub(super) fn check<'tcx>(
1818
return;
1919
}
2020

21-
if let Some(radix) = constant_full_int(cx, cx.typeck_results(), radix) {
22-
let replacement = match radix {
23-
FullInt::S(10) | FullInt::U(10) => "is_ascii_digit",
24-
FullInt::S(16) | FullInt::U(16) => "is_ascii_hexdigit",
21+
if let Some(radix_val) = constant_full_int(cx, cx.typeck_results(), radix) {
22+
let (num, replacement) = match radix_val {
23+
FullInt::S(10) | FullInt::U(10) => (10, "is_ascii_digit"),
24+
FullInt::S(16) | FullInt::U(16) => (16, "is_ascii_hexdigit"),
2525
_ => return,
2626
};
2727
let mut applicability = Applicability::MachineApplicable;
@@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
3030
cx,
3131
IS_DIGIT_ASCII_RADIX,
3232
expr.span,
33-
"use of `char::is_digit(..)` with literal radix of 10 or 16",
33+
&format!("use of `char::is_digit` with literal radix of {}", num),
3434
"try",
3535
format!(
3636
"{}.{}()",

clippy_lints/src/methods/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,9 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
24902490
},
24912491
("get_or_insert_with", [arg]) => unnecessary_lazy_eval::check(cx, expr, recv, arg, "get_or_insert"),
24922492
("is_file", []) => filetype_is_file::check(cx, expr, recv),
2493-
("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix),
2493+
("is_digit", [radix]) if meets_msrv(msrv, &msrvs::IS_ASCII_DIGIT) => {
2494+
is_digit_ascii_radix::check(cx, expr, recv, radix);
2495+
},
24942496
("is_none", []) => check_is_some_is_none(cx, expr, recv, false),
24952497
("is_some", []) => check_is_some_is_none(cx, expr, recv, true),
24962498
("join", [join_arg]) => {

clippy_utils/src/msrvs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ msrv_aliases! {
3232
1,28,0 { FROM_BOOL }
3333
1,17,0 { FIELD_INIT_SHORTHAND, STATIC_IN_CONST }
3434
1,16,0 { STR_REPEAT }
35+
1,24,0 { IS_ASCII_DIGIT }
3536
}

tests/ui/is_digit_ascii_radix.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error: use of `char::is_digit(..)` with literal radix of 10 or 16
1+
error: use of `char::is_digit` with literal radix of 10
22
--> $DIR/is_digit_ascii_radix.rs:11:13
33
|
44
LL | let _ = c.is_digit(10);
55
| ^^^^^^^^^^^^^^ help: try: `c.is_ascii_digit()`
66
|
77
= note: `-D clippy::is-digit-ascii-radix` implied by `-D warnings`
88

9-
error: use of `char::is_digit(..)` with literal radix of 10 or 16
9+
error: use of `char::is_digit` with literal radix of 16
1010
--> $DIR/is_digit_ascii_radix.rs:12:13
1111
|
1212
LL | let _ = c.is_digit(16);
1313
| ^^^^^^^^^^^^^^ help: try: `c.is_ascii_hexdigit()`
1414

15-
error: use of `char::is_digit(..)` with literal radix of 10 or 16
15+
error: use of `char::is_digit` with literal radix of 16
1616
--> $DIR/is_digit_ascii_radix.rs:13:13
1717
|
1818
LL | let _ = c.is_digit(0x10);

0 commit comments

Comments
 (0)