1
+ use clippy_config:: Conf ;
1
2
use clippy_utils:: diagnostics:: span_lint_and_sugg;
3
+ use clippy_utils:: msrvs:: { self , Msrv } ;
2
4
use clippy_utils:: source:: snippet_with_applicability;
3
- use clippy_utils:: { paths, sym} ;
5
+ use clippy_utils:: { is_in_const_context , paths, sym} ;
4
6
use rustc_errors:: Applicability ;
5
7
use rustc_hir as hir;
6
8
use rustc_lint:: { LateContext , LateLintPass } ;
7
- use rustc_session:: declare_lint_pass ;
9
+ use rustc_session:: impl_lint_pass ;
8
10
9
11
declare_clippy_lint ! {
10
12
/// ### What it does
@@ -32,7 +34,17 @@ declare_clippy_lint! {
32
34
"`char.is_digit()` is clearer"
33
35
}
34
36
35
- declare_lint_pass ! ( ToDigitIsSome => [ TO_DIGIT_IS_SOME ] ) ;
37
+ impl_lint_pass ! ( ToDigitIsSome => [ TO_DIGIT_IS_SOME ] ) ;
38
+
39
+ pub ( crate ) struct ToDigitIsSome {
40
+ msrv : Msrv ,
41
+ }
42
+
43
+ impl ToDigitIsSome {
44
+ pub ( crate ) fn new ( conf : & ' static Conf ) -> Self {
45
+ Self { msrv : conf. msrv }
46
+ }
47
+ }
36
48
37
49
impl < ' tcx > LateLintPass < ' tcx > for ToDigitIsSome {
38
50
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
@@ -59,7 +71,9 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome {
59
71
_ => None ,
60
72
} ;
61
73
62
- if let Some ( ( is_method_call, char_arg, radix_arg) ) = match_result {
74
+ if let Some ( ( is_method_call, char_arg, radix_arg) ) = match_result
75
+ && ( !is_in_const_context ( cx) || self . msrv . meets ( cx, msrvs:: CONST_CHAR_IS_DIGIT ) )
76
+ {
63
77
let mut applicability = Applicability :: MachineApplicable ;
64
78
let char_arg_snip = snippet_with_applicability ( cx, char_arg. span , "_" , & mut applicability) ;
65
79
let radix_snip = snippet_with_applicability ( cx, radix_arg. span , "_" , & mut applicability) ;
0 commit comments