@@ -7,7 +7,7 @@ use clippy_utils::{higher, is_in_const_context, path_to_local, peel_ref_operator
77use rustc_ast:: LitKind :: { Byte , Char } ;
88use rustc_ast:: ast:: RangeLimits ;
99use 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 } ;
1111use rustc_lint:: { LateContext , LateLintPass } ;
1212use rustc_middle:: ty;
1313use rustc_session:: impl_lint_pass;
@@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck {
115115 {
116116 let arg = peel_ref_operators ( cx, arg) ;
117117 let ty_sugg = get_ty_sugg ( cx, arg, start) ;
118- let range = check_range ( start, end) ;
118+ let range = check_expr_range ( start, end) ;
119119 check_is_ascii ( cx, expr. span , arg, & range, ty_sugg) ;
120120 }
121121 }
@@ -196,19 +196,34 @@ fn check_pat(pat_kind: &PatKind<'_>) -> CharRange {
196196 }
197197}
198198
199- fn check_range ( start : & Expr < ' _ > , end : & Expr < ' _ > ) -> CharRange {
199+ fn check_expr_range ( start : & Expr < ' _ > , end : & Expr < ' _ > ) -> CharRange {
200200 if let ExprKind :: Lit ( start_lit) = & start. kind
201201 && let ExprKind :: Lit ( end_lit) = & end. kind
202202 {
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)
211215 } else {
212216 CharRange :: Otherwise
213217 }
214218}
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