diff options
| author | koka <koka.code@gmail.com> | 2022-10-24 23:49:59 +0900 |
|---|---|---|
| committer | koka <koka.code@gmail.com> | 2022-11-07 16:39:36 +0900 |
| commit | e4540ad65fa14ceebd5145ab771fe4918d170bf1 (patch) | |
| tree | 41620beacd6cd5ee2c2f46975a98a6b7c1a14a9b /tests | |
| parent | 7600535511a0b8c76bf28f40e1b5c4a45a57b28f (diff) | |
feat: implement manual_is_ascii_check lint
modify fix: allow unused in test code fix: types in doc comment Update clippy_lints/src/manual_is_ascii_check.rs Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com> Update clippy_lints/src/manual_is_ascii_check.rs Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com> Update clippy_lints/src/manual_is_ascii_check.rs Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com> fix ui test result fix: unnecessary format! chore: apply feedbacks * check msrvs also for const fn * check applicability manually * modify documents
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/manual_is_ascii_check.fixed | 45 | ||||
| -rw-r--r-- | tests/ui/manual_is_ascii_check.rs | 45 | ||||
| -rw-r--r-- | tests/ui/manual_is_ascii_check.stderr | 70 |
3 files changed, 160 insertions, 0 deletions
diff --git a/tests/ui/manual_is_ascii_check.fixed b/tests/ui/manual_is_ascii_check.fixed new file mode 100644 index 00000000000..765bb785994 --- /dev/null +++ b/tests/ui/manual_is_ascii_check.fixed @@ -0,0 +1,45 @@ +// run-rustfix + +#![feature(custom_inner_attributes)] +#![allow(unused, dead_code)] +#![warn(clippy::manual_is_ascii_check)] + +fn main() { + assert!('x'.is_ascii_lowercase()); + assert!('X'.is_ascii_uppercase()); + assert!(b'x'.is_ascii_lowercase()); + assert!(b'X'.is_ascii_uppercase()); + + let num = '2'; + assert!(num.is_ascii_digit()); + assert!(b'1'.is_ascii_digit()); + assert!('x'.is_ascii_alphabetic()); + + assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_')); +} + +fn msrv_1_23() { + #![clippy::msrv = "1.23"] + + assert!(matches!(b'1', b'0'..=b'9')); + assert!(matches!('X', 'A'..='Z')); + assert!(matches!('x', 'A'..='Z' | 'a'..='z')); +} + +fn msrv_1_24() { + #![clippy::msrv = "1.24"] + + assert!(b'1'.is_ascii_digit()); + assert!('X'.is_ascii_uppercase()); + assert!('x'.is_ascii_alphabetic()); +} + +fn msrv_1_46() { + #![clippy::msrv = "1.46"] + const FOO: bool = matches!('x', '0'..='9'); +} + +fn msrv_1_47() { + #![clippy::msrv = "1.47"] + const FOO: bool = 'x'.is_ascii_digit(); +} diff --git a/tests/ui/manual_is_ascii_check.rs b/tests/ui/manual_is_ascii_check.rs new file mode 100644 index 00000000000..be133161041 --- /dev/null +++ b/tests/ui/manual_is_ascii_check.rs @@ -0,0 +1,45 @@ +// run-rustfix + +#![feature(custom_inner_attributes)] +#![allow(unused, dead_code)] +#![warn(clippy::manual_is_ascii_check)] + +fn main() { + assert!(matches!('x', 'a'..='z')); + assert!(matches!('X', 'A'..='Z')); + assert!(matches!(b'x', b'a'..=b'z')); + assert!(matches!(b'X', b'A'..=b'Z')); + + let num = '2'; + assert!(matches!(num, '0'..='9')); + assert!(matches!(b'1', b'0'..=b'9')); + assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + + assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_')); +} + +fn msrv_1_23() { + #![clippy::msrv = "1.23"] + + assert!(matches!(b'1', b'0'..=b'9')); + assert!(matches!('X', 'A'..='Z')); + assert!(matches!('x', 'A'..='Z' | 'a'..='z')); +} + +fn msrv_1_24() { + #![clippy::msrv = "1.24"] + + assert!(matches!(b'1', b'0'..=b'9')); + assert!(matches!('X', 'A'..='Z')); + assert!(matches!('x', 'A'..='Z' | 'a'..='z')); +} + +fn msrv_1_46() { + #![clippy::msrv = "1.46"] + const FOO: bool = matches!('x', '0'..='9'); +} + +fn msrv_1_47() { + #![clippy::msrv = "1.47"] + const FOO: bool = matches!('x', '0'..='9'); +} diff --git a/tests/ui/manual_is_ascii_check.stderr b/tests/ui/manual_is_ascii_check.stderr new file mode 100644 index 00000000000..c0a9d4db1a1 --- /dev/null +++ b/tests/ui/manual_is_ascii_check.stderr @@ -0,0 +1,70 @@ +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:8:13 + | +LL | assert!(matches!('x', 'a'..='z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_lowercase()` + | + = note: `-D clippy::manual-is-ascii-check` implied by `-D warnings` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:9:13 + | +LL | assert!(matches!('X', 'A'..='Z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:10:13 + | +LL | assert!(matches!(b'x', b'a'..=b'z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'x'.is_ascii_lowercase()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:11:13 + | +LL | assert!(matches!(b'X', b'A'..=b'Z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'X'.is_ascii_uppercase()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:14:13 + | +LL | assert!(matches!(num, '0'..='9')); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.is_ascii_digit()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:15:13 + | +LL | assert!(matches!(b'1', b'0'..=b'9')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:16:13 + | +LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:32:13 + | +LL | assert!(matches!(b'1', b'0'..=b'9')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:33:13 + | +LL | assert!(matches!('X', 'A'..='Z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:34:13 + | +LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` + +error: manual check for common ascii range + --> $DIR/manual_is_ascii_check.rs:44:23 + | +LL | const FOO: bool = matches!('x', '0'..='9'); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()` + +error: aborting due to 11 previous errors + |
