@@ -7,7 +7,7 @@ use clippy_utils::{higher, is_in_const_context, path_to_local, peel_ref_operator
7
7
use rustc_ast:: LitKind :: { Byte , Char } ;
8
8
use rustc_ast:: ast:: RangeLimits ;
9
9
use rustc_errors:: Applicability ;
10
- use rustc_hir:: { Expr , ExprKind , Node , Param , PatKind , RangeEnd } ;
10
+ use rustc_hir:: { Expr , ExprKind , Node , Param , PatKind , RangeEnd , PatExpr , PatExprKind , Lit } ;
11
11
use rustc_lint:: { LateContext , LateLintPass } ;
12
12
use rustc_middle:: ty;
13
13
use rustc_session:: impl_lint_pass;
@@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck {
115
115
{
116
116
let arg = peel_ref_operators ( cx, arg) ;
117
117
let ty_sugg = get_ty_sugg ( cx, arg, start) ;
118
- let range = check_range ( start, end) ;
118
+ let range = check_expr_range ( start, end) ;
119
119
check_is_ascii ( cx, expr. span , arg, & range, ty_sugg) ;
120
120
}
121
121
}
@@ -196,19 +196,34 @@ fn check_pat(pat_kind: &PatKind<'_>) -> CharRange {
196
196
}
197
197
}
198
198
199
- fn check_range ( start : & Expr < ' _ > , end : & Expr < ' _ > ) -> CharRange {
199
+ fn check_expr_range ( start : & Expr < ' _ > , end : & Expr < ' _ > ) -> CharRange {
200
200
if let ExprKind :: Lit ( start_lit) = & start. kind
201
201
&& let ExprKind :: Lit ( end_lit) = & end. kind
202
202
{
203
- match ( & start_lit. node , & end_lit. node ) {
204
- ( Char ( 'a' ) , Char ( 'z' ) ) | ( Byte ( b'a' ) , Byte ( b'z' ) ) => CharRange :: LowerChar ,
205
- ( Char ( 'A' ) , Char ( 'Z' ) ) | ( Byte ( b'A' ) , Byte ( b'Z' ) ) => CharRange :: UpperChar ,
206
- ( Char ( 'a' ) , Char ( 'f' ) ) | ( Byte ( b'a' ) , Byte ( b'f' ) ) => CharRange :: LowerHexLetter ,
207
- ( Char ( 'A' ) , Char ( 'F' ) ) | ( Byte ( b'A' ) , Byte ( b'F' ) ) => CharRange :: UpperHexLetter ,
208
- ( Char ( '0' ) , Char ( '9' ) ) | ( Byte ( b'0' ) , Byte ( b'9' ) ) => CharRange :: Digit ,
209
- _ => CharRange :: Otherwise ,
210
- }
203
+ check_lit_range ( start_lit, end_lit)
204
+ } else {
205
+ CharRange :: Otherwise
206
+ }
207
+ }
208
+
209
+
210
+ fn check_range ( start : & PatExpr < ' _ > , end : & PatExpr < ' _ > ) -> CharRange {
211
+ if let PatExprKind :: Lit { lit : start_lit, negated : false } = & start. kind
212
+ && let PatExprKind :: Lit { lit : end_lit, negated : false } = & end. kind
213
+ {
214
+ check_lit_range ( start_lit, end_lit)
211
215
} else {
212
216
CharRange :: Otherwise
213
217
}
214
218
}
219
+
220
+ fn check_lit_range ( start_lit : & Lit , end_lit : & Lit ) -> CharRange {
221
+ match ( & start_lit. node , & end_lit. node ) {
222
+ ( Char ( 'a' ) , Char ( 'z' ) ) | ( Byte ( b'a' ) , Byte ( b'z' ) ) => CharRange :: LowerChar ,
223
+ ( Char ( 'A' ) , Char ( 'Z' ) ) | ( Byte ( b'A' ) , Byte ( b'Z' ) ) => CharRange :: UpperChar ,
224
+ ( Char ( 'a' ) , Char ( 'f' ) ) | ( Byte ( b'a' ) , Byte ( b'f' ) ) => CharRange :: LowerHexLetter ,
225
+ ( Char ( 'A' ) , Char ( 'F' ) ) | ( Byte ( b'A' ) , Byte ( b'F' ) ) => CharRange :: UpperHexLetter ,
226
+ ( Char ( '0' ) , Char ( '9' ) ) | ( Byte ( b'0' ) , Byte ( b'9' ) ) => CharRange :: Digit ,
227
+ _ => CharRange :: Otherwise ,
228
+ }
229
+ }
0 commit comments