Skip to content

Commit

Permalink
MSRV and more specific message
Browse files Browse the repository at this point in the history
  • Loading branch information
pitaj committed Apr 5, 2022
1 parent 44c084b commit d020b6f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
10 changes: 5 additions & 5 deletions clippy_lints/src/methods/is_digit_ascii_radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ pub(super) fn check<'tcx>(
return;
}

if let Some(radix) = constant_full_int(cx, cx.typeck_results(), radix) {
let replacement = match radix {
FullInt::S(10) | FullInt::U(10) => "is_ascii_digit",
FullInt::S(16) | FullInt::U(16) => "is_ascii_hexdigit",
if let Some(radix_val) = constant_full_int(cx, cx.typeck_results(), radix) {
let (num, replacement) = match radix_val {
FullInt::S(10) | FullInt::U(10) => (10, "is_ascii_digit"),
FullInt::S(16) | FullInt::U(16) => (16, "is_ascii_hexdigit"),
_ => return,
};
let mut applicability = Applicability::MachineApplicable;
Expand All @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
cx,
IS_DIGIT_ASCII_RADIX,
expr.span,
"use of `char::is_digit(..)` with literal radix of 10 or 16",
&format!("use of `char::is_digit` with literal radix of {}", num),
"try",
format!(
"{}.{}()",
Expand Down
4 changes: 3 additions & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,9 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
},
("get_or_insert_with", [arg]) => unnecessary_lazy_eval::check(cx, expr, recv, arg, "get_or_insert"),
("is_file", []) => filetype_is_file::check(cx, expr, recv),
("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix),
("is_digit", [radix]) if meets_msrv(msrv, &msrvs::IS_ASCII_DIGIT) => {
is_digit_ascii_radix::check(cx, expr, recv, radix);
},
("is_none", []) => check_is_some_is_none(cx, expr, recv, false),
("is_some", []) => check_is_some_is_none(cx, expr, recv, true),
("join", [join_arg]) => {
Expand Down
1 change: 1 addition & 0 deletions clippy_utils/src/msrvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ msrv_aliases! {
1,28,0 { FROM_BOOL }
1,17,0 { FIELD_INIT_SHORTHAND, STATIC_IN_CONST }
1,16,0 { STR_REPEAT }
1,24,0 { IS_ASCII_DIGIT }
}
6 changes: 3 additions & 3 deletions tests/ui/is_digit_ascii_radix.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: use of `char::is_digit(..)` with literal radix of 10 or 16
error: use of `char::is_digit` with literal radix of 10
--> $DIR/is_digit_ascii_radix.rs:11:13
|
LL | let _ = c.is_digit(10);
| ^^^^^^^^^^^^^^ help: try: `c.is_ascii_digit()`
|
= note: `-D clippy::is-digit-ascii-radix` implied by `-D warnings`

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

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

0 comments on commit d020b6f

Please sign in to comment.