1+ use clippy_config:: Conf ;
12use clippy_utils:: diagnostics:: span_lint_and_sugg;
3+ use clippy_utils:: msrvs:: { self , Msrv } ;
24use clippy_utils:: source:: snippet_with_applicability;
3- use clippy_utils:: { paths, sym} ;
5+ use clippy_utils:: { is_in_const_context , paths, sym} ;
46use rustc_errors:: Applicability ;
57use rustc_hir as hir;
68use rustc_lint:: { LateContext , LateLintPass } ;
7- use rustc_session:: declare_lint_pass ;
9+ use rustc_session:: impl_lint_pass ;
810
911declare_clippy_lint ! {
1012 /// ### What it does
@@ -32,7 +34,17 @@ declare_clippy_lint! {
3234 "`char.is_digit()` is clearer"
3335}
3436
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+ }
3648
3749impl < ' tcx > LateLintPass < ' tcx > for ToDigitIsSome {
3850 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
@@ -59,7 +71,9 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome {
5971 _ => None ,
6072 } ;
6173
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+ {
6377 let mut applicability = Applicability :: MachineApplicable ;
6478 let char_arg_snip = snippet_with_applicability ( cx, char_arg. span , "_" , & mut applicability) ;
6579 let radix_snip = snippet_with_applicability ( cx, radix_arg. span , "_" , & mut applicability) ;
0 commit comments