1 //! Lint for `c.is_digit(10)`
3 use super::IS_DIGIT_ASCII_RADIX;
5 consts::constant_full_int, consts::FullInt, diagnostics::span_lint_and_sugg, meets_msrv, msrvs,
6 source::snippet_with_applicability,
8 use rustc_errors::Applicability;
10 use rustc_lint::LateContext;
11 use rustc_semver::RustcVersion;
13 pub(super) fn check<'tcx>(
14 cx: &LateContext<'tcx>,
16 self_arg: &'tcx Expr<'_>,
17 radix: &'tcx Expr<'_>,
18 msrv: Option<&RustcVersion>,
20 if !meets_msrv(msrv, &msrvs::IS_ASCII_DIGIT) {
24 if !cx.typeck_results().expr_ty_adjusted(self_arg).peel_refs().is_char() {
28 if let Some(radix_val) = constant_full_int(cx, cx.typeck_results(), radix) {
29 let (num, replacement) = match radix_val {
30 FullInt::S(10) | FullInt::U(10) => (10, "is_ascii_digit"),
31 FullInt::S(16) | FullInt::U(16) => (16, "is_ascii_hexdigit"),
34 let mut applicability = Applicability::MachineApplicable;
40 &format!("use of `char::is_digit` with literal radix of {}", num),
44 snippet_with_applicability(cx, self_arg.span, "..", &mut applicability),