mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
add more test, limits check
This commit is contained in:
parent
25c9718c04
commit
de92da2974
@ -1,5 +1,6 @@
|
|||||||
use clippy_utils::msrvs::{self, Msrv};
|
use clippy_utils::msrvs::{self, Msrv};
|
||||||
use clippy_utils::{diagnostics::span_lint_and_sugg, higher, in_constant, macros::root_macro_call, source::snippet};
|
use clippy_utils::{diagnostics::span_lint_and_sugg, higher, in_constant, macros::root_macro_call, source::snippet};
|
||||||
|
use rustc_ast::ast::RangeLimits;
|
||||||
use rustc_ast::LitKind::{Byte, Char};
|
use rustc_ast::LitKind::{Byte, Char};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Expr, ExprKind, PatKind, RangeEnd};
|
use rustc_hir::{Expr, ExprKind, PatKind, RangeEnd};
|
||||||
@ -83,7 +84,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck {
|
|||||||
}
|
}
|
||||||
} else if let ExprKind::MethodCall(path, receiver, [arg], ..) = expr.kind
|
} else if let ExprKind::MethodCall(path, receiver, [arg], ..) = expr.kind
|
||||||
&& path.ident.name == sym!(contains)
|
&& path.ident.name == sym!(contains)
|
||||||
&& let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::Range::hir(receiver) {
|
&& let Some(higher::Range { start: Some(start), end: Some(end), limits: RangeLimits::Closed })
|
||||||
|
= higher::Range::hir(receiver) {
|
||||||
let range = check_range(start, end);
|
let range = check_range(start, end);
|
||||||
check_is_ascii(cx, expr.span, arg, &range);
|
check_is_ascii(cx, expr.span, arg, &range);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,14 @@ fn main() {
|
|||||||
assert!('x'.is_ascii_alphabetic());
|
assert!('x'.is_ascii_alphabetic());
|
||||||
|
|
||||||
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
|
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
|
||||||
|
|
||||||
assert!(&b'0'.is_ascii_digit());
|
assert!(&b'0'.is_ascii_digit());
|
||||||
|
assert!(&b'a'.is_ascii_lowercase());
|
||||||
|
assert!(&b'A'.is_ascii_uppercase());
|
||||||
|
|
||||||
|
assert!(&'0'.is_ascii_digit());
|
||||||
|
assert!(&'a'.is_ascii_lowercase());
|
||||||
|
assert!(&'A'.is_ascii_uppercase());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[clippy::msrv = "1.23"]
|
#[clippy::msrv = "1.23"]
|
||||||
|
@ -15,7 +15,14 @@ fn main() {
|
|||||||
assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
||||||
|
|
||||||
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
|
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
|
||||||
|
|
||||||
assert!((b'0'..=b'9').contains(&b'0'));
|
assert!((b'0'..=b'9').contains(&b'0'));
|
||||||
|
assert!((b'a'..=b'z').contains(&b'a'));
|
||||||
|
assert!((b'A'..=b'Z').contains(&b'A'));
|
||||||
|
|
||||||
|
assert!(('0'..='9').contains(&'0'));
|
||||||
|
assert!(('a'..='z').contains(&'a'));
|
||||||
|
assert!(('A'..='Z').contains(&'A'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[clippy::msrv = "1.23"]
|
#[clippy::msrv = "1.23"]
|
||||||
|
@ -43,34 +43,64 @@ LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
|
||||||
|
|
||||||
error: manual check for common ascii range
|
error: manual check for common ascii range
|
||||||
--> $DIR/manual_is_ascii_check.rs:18:13
|
--> $DIR/manual_is_ascii_check.rs:19:13
|
||||||
|
|
|
|
||||||
LL | assert!((b'0'..=b'9').contains(&b'0'));
|
LL | assert!((b'0'..=b'9').contains(&b'0'));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&b'0'.is_ascii_digit()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&b'0'.is_ascii_digit()`
|
||||||
|
|
||||||
error: manual check for common ascii range
|
error: manual check for common ascii range
|
||||||
--> $DIR/manual_is_ascii_check.rs:30:13
|
--> $DIR/manual_is_ascii_check.rs:20:13
|
||||||
|
|
|
||||||
|
LL | assert!((b'a'..=b'z').contains(&b'a'));
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&b'a'.is_ascii_lowercase()`
|
||||||
|
|
||||||
|
error: manual check for common ascii range
|
||||||
|
--> $DIR/manual_is_ascii_check.rs:21:13
|
||||||
|
|
|
||||||
|
LL | assert!((b'A'..=b'Z').contains(&b'A'));
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&b'A'.is_ascii_uppercase()`
|
||||||
|
|
||||||
|
error: manual check for common ascii range
|
||||||
|
--> $DIR/manual_is_ascii_check.rs:23:13
|
||||||
|
|
|
||||||
|
LL | assert!(('0'..='9').contains(&'0'));
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'0'.is_ascii_digit()`
|
||||||
|
|
||||||
|
error: manual check for common ascii range
|
||||||
|
--> $DIR/manual_is_ascii_check.rs:24:13
|
||||||
|
|
|
||||||
|
LL | assert!(('a'..='z').contains(&'a'));
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a'.is_ascii_lowercase()`
|
||||||
|
|
||||||
|
error: manual check for common ascii range
|
||||||
|
--> $DIR/manual_is_ascii_check.rs:25:13
|
||||||
|
|
|
||||||
|
LL | assert!(('A'..='Z').contains(&'A'));
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'A'.is_ascii_uppercase()`
|
||||||
|
|
||||||
|
error: manual check for common ascii range
|
||||||
|
--> $DIR/manual_is_ascii_check.rs:37:13
|
||||||
|
|
|
|
||||||
LL | assert!(matches!(b'1', b'0'..=b'9'));
|
LL | assert!(matches!(b'1', b'0'..=b'9'));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()`
|
||||||
|
|
||||||
error: manual check for common ascii range
|
error: manual check for common ascii range
|
||||||
--> $DIR/manual_is_ascii_check.rs:31:13
|
--> $DIR/manual_is_ascii_check.rs:38:13
|
||||||
|
|
|
|
||||||
LL | assert!(matches!('X', 'A'..='Z'));
|
LL | assert!(matches!('X', 'A'..='Z'));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()`
|
||||||
|
|
||||||
error: manual check for common ascii range
|
error: manual check for common ascii range
|
||||||
--> $DIR/manual_is_ascii_check.rs:32:13
|
--> $DIR/manual_is_ascii_check.rs:39:13
|
||||||
|
|
|
|
||||||
LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
|
||||||
|
|
||||||
error: manual check for common ascii range
|
error: manual check for common ascii range
|
||||||
--> $DIR/manual_is_ascii_check.rs:42:23
|
--> $DIR/manual_is_ascii_check.rs:49:23
|
||||||
|
|
|
|
||||||
LL | const FOO: bool = matches!('x', '0'..='9');
|
LL | const FOO: bool = matches!('x', '0'..='9');
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()`
|
||||||
|
|
||||||
error: aborting due to 12 previous errors
|
error: aborting due to 17 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user