Skip to content

Commit 1f862c2

Browse files
naosensenaosense
authored andcommitted
remove assert macro
1 parent 949d070 commit 1f862c2

File tree

4 files changed

+71
-51
lines changed

4 files changed

+71
-51
lines changed

clippy_lints/src/manual_is_ascii_check.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ declare_clippy_lint! {
2525
/// assert!(matches!('2', '0'..='9'));
2626
/// assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
2727
///
28-
/// assert!((b'0'..=b'9').contains(&b'0'));
29-
/// assert!((b'a'..=b'z').contains(&b'a'));
30-
/// assert!((b'A'..=b'Z').contains(&b'A'));
31-
///
32-
/// assert!(('0'..='9').contains(&'0'));
33-
/// assert!(('a'..='z').contains(&'a'));
34-
/// assert!(('A'..='Z').contains(&'A'));
28+
/// ('0'..='9').contains(&'0');
29+
/// ('a'..='z').contains(&'a');
30+
/// ('A'..='Z').contains(&'A');
3531
/// }
3632
/// ```
3733
/// Use instead:
@@ -42,13 +38,9 @@ declare_clippy_lint! {
4238
/// assert!('2'.is_ascii_digit());
4339
/// assert!('x'.is_ascii_alphabetic());
4440
///
45-
/// assert!(b'0'.is_ascii_digit());
46-
/// assert!(b'a'.is_ascii_lowercase());
47-
/// assert!(b'A'.is_ascii_uppercase());
48-
///
49-
/// assert!('0'.is_ascii_digit());
50-
/// assert!('a'.is_ascii_lowercase());
51-
/// assert!('A'.is_ascii_uppercase());
41+
/// '0'.is_ascii_digit();
42+
/// 'a'.is_ascii_lowercase();
43+
/// 'A'.is_ascii_uppercase();
5244
/// }
5345
/// ```
5446
#[clippy::version = "1.66.0"]

tests/ui/manual_is_ascii_check.fixed

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ fn main() {
1616

1717
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
1818

19-
assert!(b'0'.is_ascii_digit());
20-
assert!(b'a'.is_ascii_lowercase());
21-
assert!(b'A'.is_ascii_uppercase());
22-
23-
assert!('0'.is_ascii_digit());
24-
assert!('a'.is_ascii_lowercase());
25-
assert!('A'.is_ascii_uppercase());
19+
b'0'.is_ascii_digit();
20+
b'a'.is_ascii_lowercase();
21+
b'A'.is_ascii_uppercase();
22+
23+
'0'.is_ascii_digit();
24+
'a'.is_ascii_lowercase();
25+
'A'.is_ascii_uppercase();
26+
27+
let cool_letter = &'g';
28+
cool_letter.is_ascii_digit();
29+
cool_letter.is_ascii_lowercase();
30+
cool_letter.is_ascii_uppercase();
2631
}
2732

2833
#[clippy::msrv = "1.23"]

tests/ui/manual_is_ascii_check.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ fn main() {
1616

1717
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
1818

19-
assert!((b'0'..=b'9').contains(&b'0'));
20-
assert!((b'a'..=b'z').contains(&b'a'));
21-
assert!((b'A'..=b'Z').contains(&b'A'));
22-
23-
assert!(('0'..='9').contains(&'0'));
24-
assert!(('a'..='z').contains(&'a'));
25-
assert!(('A'..='Z').contains(&'A'));
19+
(b'0'..=b'9').contains(&b'0');
20+
(b'a'..=b'z').contains(&b'a');
21+
(b'A'..=b'Z').contains(&b'A');
22+
23+
('0'..='9').contains(&'0');
24+
('a'..='z').contains(&'a');
25+
('A'..='Z').contains(&'A');
26+
27+
let cool_letter = &'g';
28+
('0'..='9').contains(cool_letter);
29+
('a'..='z').contains(cool_letter);
30+
('A'..='Z').contains(cool_letter);
2631
}
2732

2833
#[clippy::msrv = "1.23"]

tests/ui/manual_is_ascii_check.stderr

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,64 +43,82 @@ LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
4444

4545
error: manual check for common ascii range
46-
--> $DIR/manual_is_ascii_check.rs:19:13
46+
--> $DIR/manual_is_ascii_check.rs:19:5
4747
|
48-
LL | assert!((b'0'..=b'9').contains(&b'0'));
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'0'.is_ascii_digit()`
48+
LL | (b'0'..=b'9').contains(&b'0');
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'0'.is_ascii_digit()`
5050

5151
error: manual check for common ascii range
52-
--> $DIR/manual_is_ascii_check.rs:20:13
52+
--> $DIR/manual_is_ascii_check.rs:20:5
5353
|
54-
LL | assert!((b'a'..=b'z').contains(&b'a'));
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'a'.is_ascii_lowercase()`
54+
LL | (b'a'..=b'z').contains(&b'a');
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'a'.is_ascii_lowercase()`
5656

5757
error: manual check for common ascii range
58-
--> $DIR/manual_is_ascii_check.rs:21:13
58+
--> $DIR/manual_is_ascii_check.rs:21:5
5959
|
60-
LL | assert!((b'A'..=b'Z').contains(&b'A'));
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'A'.is_ascii_uppercase()`
60+
LL | (b'A'..=b'Z').contains(&b'A');
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'A'.is_ascii_uppercase()`
6262

6363
error: manual check for common ascii range
64-
--> $DIR/manual_is_ascii_check.rs:23:13
64+
--> $DIR/manual_is_ascii_check.rs:23:5
6565
|
66-
LL | assert!(('0'..='9').contains(&'0'));
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'0'.is_ascii_digit()`
66+
LL | ('0'..='9').contains(&'0');
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'0'.is_ascii_digit()`
6868

6969
error: manual check for common ascii range
70-
--> $DIR/manual_is_ascii_check.rs:24:13
70+
--> $DIR/manual_is_ascii_check.rs:24:5
7171
|
72-
LL | assert!(('a'..='z').contains(&'a'));
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'a'.is_ascii_lowercase()`
72+
LL | ('a'..='z').contains(&'a');
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'a'.is_ascii_lowercase()`
7474

7575
error: manual check for common ascii range
76-
--> $DIR/manual_is_ascii_check.rs:25:13
76+
--> $DIR/manual_is_ascii_check.rs:25:5
7777
|
78-
LL | assert!(('A'..='Z').contains(&'A'));
79-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'A'.is_ascii_uppercase()`
78+
LL | ('A'..='Z').contains(&'A');
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'A'.is_ascii_uppercase()`
8080

8181
error: manual check for common ascii range
82-
--> $DIR/manual_is_ascii_check.rs:37:13
82+
--> $DIR/manual_is_ascii_check.rs:28:5
83+
|
84+
LL | ('0'..='9').contains(cool_letter);
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_digit()`
86+
87+
error: manual check for common ascii range
88+
--> $DIR/manual_is_ascii_check.rs:29:5
89+
|
90+
LL | ('a'..='z').contains(cool_letter);
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_lowercase()`
92+
93+
error: manual check for common ascii range
94+
--> $DIR/manual_is_ascii_check.rs:30:5
95+
|
96+
LL | ('A'..='Z').contains(cool_letter);
97+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_uppercase()`
98+
99+
error: manual check for common ascii range
100+
--> $DIR/manual_is_ascii_check.rs:42:13
83101
|
84102
LL | assert!(matches!(b'1', b'0'..=b'9'));
85103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()`
86104

87105
error: manual check for common ascii range
88-
--> $DIR/manual_is_ascii_check.rs:38:13
106+
--> $DIR/manual_is_ascii_check.rs:43:13
89107
|
90108
LL | assert!(matches!('X', 'A'..='Z'));
91109
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()`
92110

93111
error: manual check for common ascii range
94-
--> $DIR/manual_is_ascii_check.rs:39:13
112+
--> $DIR/manual_is_ascii_check.rs:44:13
95113
|
96114
LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
97115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
98116

99117
error: manual check for common ascii range
100-
--> $DIR/manual_is_ascii_check.rs:49:23
118+
--> $DIR/manual_is_ascii_check.rs:54:23
101119
|
102120
LL | const FOO: bool = matches!('x', '0'..='9');
103121
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()`
104122

105-
error: aborting due to 17 previous errors
123+
error: aborting due to 20 previous errors
106124

0 commit comments

Comments
 (0)