Skip to content

Commit 7498a5f

Browse files
committed
Auto merge of #4276 - phansch:uitestcleanup, r=flip1995
UI Test Cleanup: Split up checked_unwrap tests Let's slowly bring that ticket closer to the finish line 🐌 🏁 This splits up `tests/ui/checked_unwrap.rs` into: * `tests/ui/checked_unwrap/complex.rs` * `tests/ui/checked_unwrap/simple.rs` Based on the naming of the methods in the tests. changelog: none cc #2038
2 parents 164310d + 48bff49 commit 7498a5f

File tree

4 files changed

+191
-173
lines changed

4 files changed

+191
-173
lines changed

tests/ui/checked_unwrap.rs renamed to tests/ui/checked_unwrap/complex_conditionals.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
11
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
22
#![allow(clippy::if_same_then_else)]
33

4-
fn main() {
5-
let x = Some(());
6-
if x.is_some() {
7-
x.unwrap(); // unnecessary
8-
} else {
9-
x.unwrap(); // will panic
10-
}
11-
if x.is_none() {
12-
x.unwrap(); // will panic
13-
} else {
14-
x.unwrap(); // unnecessary
15-
}
16-
let mut x: Result<(), ()> = Ok(());
17-
if x.is_ok() {
18-
x.unwrap(); // unnecessary
19-
x.unwrap_err(); // will panic
20-
} else {
21-
x.unwrap(); // will panic
22-
x.unwrap_err(); // unnecessary
23-
}
24-
if x.is_err() {
25-
x.unwrap(); // will panic
26-
x.unwrap_err(); // unnecessary
27-
} else {
28-
x.unwrap(); // unnecessary
29-
x.unwrap_err(); // will panic
30-
}
31-
if x.is_ok() {
32-
x = Err(());
33-
x.unwrap(); // not unnecessary because of mutation of x
34-
// it will always panic but the lint is not smart enough to see this (it only checks if conditions).
35-
} else {
36-
x = Ok(());
37-
x.unwrap_err(); // not unnecessary because of mutation of x
38-
// it will always panic but the lint is not smart enough to see this (it only checks if conditions).
39-
}
40-
}
41-
424
fn test_complex_conditions() {
435
let x: Result<(), ()> = Ok(());
446
let y: Result<(), ()> = Ok(());
@@ -99,3 +61,5 @@ fn test_nested() {
9961
}
10062
}
10163
}
64+
65+
fn main() {}
Lines changed: 31 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,34 @@
11
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
2-
--> $DIR/checked_unwrap.rs:7:9
2+
--> $DIR/complex_conditionals.rs:8:9
33
|
4-
LL | if x.is_some() {
5-
| ----------- the check is happening here
4+
LL | if x.is_ok() && y.is_err() {
5+
| --------- the check is happening here
66
LL | x.unwrap(); // unnecessary
77
| ^^^^^^^^^^
88
|
99
note: lint level defined here
10-
--> $DIR/checked_unwrap.rs:1:35
10+
--> $DIR/complex_conditionals.rs:1:35
1111
|
1212
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

15-
error: This call to `unwrap()` will always panic.
16-
--> $DIR/checked_unwrap.rs:9:9
17-
|
18-
LL | if x.is_some() {
19-
| ----------- because of this check
20-
...
21-
LL | x.unwrap(); // will panic
22-
| ^^^^^^^^^^
23-
|
24-
note: lint level defined here
25-
--> $DIR/checked_unwrap.rs:1:9
26-
|
27-
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^
29-
30-
error: This call to `unwrap()` will always panic.
31-
--> $DIR/checked_unwrap.rs:12:9
32-
|
33-
LL | if x.is_none() {
34-
| ----------- because of this check
35-
LL | x.unwrap(); // will panic
36-
| ^^^^^^^^^^
37-
38-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
39-
--> $DIR/checked_unwrap.rs:14:9
40-
|
41-
LL | if x.is_none() {
42-
| ----------- the check is happening here
43-
...
44-
LL | x.unwrap(); // unnecessary
45-
| ^^^^^^^^^^
46-
47-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
48-
--> $DIR/checked_unwrap.rs:18:9
49-
|
50-
LL | if x.is_ok() {
51-
| --------- the check is happening here
52-
LL | x.unwrap(); // unnecessary
53-
| ^^^^^^^^^^
54-
5515
error: This call to `unwrap_err()` will always panic.
56-
--> $DIR/checked_unwrap.rs:19:9
16+
--> $DIR/complex_conditionals.rs:9:9
5717
|
58-
LL | if x.is_ok() {
59-
| --------- because of this check
60-
LL | x.unwrap(); // unnecessary
61-
LL | x.unwrap_err(); // will panic
62-
| ^^^^^^^^^^^^^^
63-
64-
error: This call to `unwrap()` will always panic.
65-
--> $DIR/checked_unwrap.rs:21:9
66-
|
67-
LL | if x.is_ok() {
18+
LL | if x.is_ok() && y.is_err() {
6819
| --------- because of this check
69-
...
70-
LL | x.unwrap(); // will panic
71-
| ^^^^^^^^^^
72-
73-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
74-
--> $DIR/checked_unwrap.rs:22:9
75-
|
76-
LL | if x.is_ok() {
77-
| --------- the check is happening here
78-
...
79-
LL | x.unwrap_err(); // unnecessary
80-
| ^^^^^^^^^^^^^^
81-
82-
error: This call to `unwrap()` will always panic.
83-
--> $DIR/checked_unwrap.rs:25:9
84-
|
85-
LL | if x.is_err() {
86-
| ---------- because of this check
87-
LL | x.unwrap(); // will panic
88-
| ^^^^^^^^^^
89-
90-
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
91-
--> $DIR/checked_unwrap.rs:26:9
92-
|
93-
LL | if x.is_err() {
94-
| ---------- the check is happening here
95-
LL | x.unwrap(); // will panic
96-
LL | x.unwrap_err(); // unnecessary
97-
| ^^^^^^^^^^^^^^
98-
99-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
100-
--> $DIR/checked_unwrap.rs:28:9
101-
|
102-
LL | if x.is_err() {
103-
| ---------- the check is happening here
104-
...
10520
LL | x.unwrap(); // unnecessary
106-
| ^^^^^^^^^^
107-
108-
error: This call to `unwrap_err()` will always panic.
109-
--> $DIR/checked_unwrap.rs:29:9
110-
|
111-
LL | if x.is_err() {
112-
| ---------- because of this check
113-
...
11421
LL | x.unwrap_err(); // will panic
11522
| ^^^^^^^^^^^^^^
116-
117-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
118-
--> $DIR/checked_unwrap.rs:46:9
11923
|
120-
LL | if x.is_ok() && y.is_err() {
121-
| --------- the check is happening here
122-
LL | x.unwrap(); // unnecessary
123-
| ^^^^^^^^^^
124-
125-
error: This call to `unwrap_err()` will always panic.
126-
--> $DIR/checked_unwrap.rs:47:9
24+
note: lint level defined here
25+
--> $DIR/complex_conditionals.rs:1:9
12726
|
128-
LL | if x.is_ok() && y.is_err() {
129-
| --------- because of this check
130-
LL | x.unwrap(); // unnecessary
131-
LL | x.unwrap_err(); // will panic
132-
| ^^^^^^^^^^^^^^
27+
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^
13329

13430
error: This call to `unwrap()` will always panic.
135-
--> $DIR/checked_unwrap.rs:48:9
31+
--> $DIR/complex_conditionals.rs:10:9
13632
|
13733
LL | if x.is_ok() && y.is_err() {
13834
| ---------- because of this check
@@ -141,7 +37,7 @@ LL | y.unwrap(); // will panic
14137
| ^^^^^^^^^^
14238

14339
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
144-
--> $DIR/checked_unwrap.rs:49:9
40+
--> $DIR/complex_conditionals.rs:11:9
14541
|
14642
LL | if x.is_ok() && y.is_err() {
14743
| ---------- the check is happening here
@@ -150,7 +46,7 @@ LL | y.unwrap_err(); // unnecessary
15046
| ^^^^^^^^^^^^^^
15147

15248
error: This call to `unwrap()` will always panic.
153-
--> $DIR/checked_unwrap.rs:63:9
49+
--> $DIR/complex_conditionals.rs:25:9
15450
|
15551
LL | if x.is_ok() || y.is_ok() {
15652
| --------- because of this check
@@ -159,7 +55,7 @@ LL | x.unwrap(); // will panic
15955
| ^^^^^^^^^^
16056

16157
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
162-
--> $DIR/checked_unwrap.rs:64:9
58+
--> $DIR/complex_conditionals.rs:26:9
16359
|
16460
LL | if x.is_ok() || y.is_ok() {
16561
| --------- the check is happening here
@@ -168,7 +64,7 @@ LL | x.unwrap_err(); // unnecessary
16864
| ^^^^^^^^^^^^^^
16965

17066
error: This call to `unwrap()` will always panic.
171-
--> $DIR/checked_unwrap.rs:65:9
67+
--> $DIR/complex_conditionals.rs:27:9
17268
|
17369
LL | if x.is_ok() || y.is_ok() {
17470
| --------- because of this check
@@ -177,7 +73,7 @@ LL | y.unwrap(); // will panic
17773
| ^^^^^^^^^^
17874

17975
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
180-
--> $DIR/checked_unwrap.rs:66:9
76+
--> $DIR/complex_conditionals.rs:28:9
18177
|
18278
LL | if x.is_ok() || y.is_ok() {
18379
| --------- the check is happening here
@@ -186,15 +82,15 @@ LL | y.unwrap_err(); // unnecessary
18682
| ^^^^^^^^^^^^^^
18783

18884
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
189-
--> $DIR/checked_unwrap.rs:70:9
85+
--> $DIR/complex_conditionals.rs:32:9
19086
|
19187
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
19288
| --------- the check is happening here
19389
LL | x.unwrap(); // unnecessary
19490
| ^^^^^^^^^^
19591

19692
error: This call to `unwrap_err()` will always panic.
197-
--> $DIR/checked_unwrap.rs:71:9
93+
--> $DIR/complex_conditionals.rs:33:9
19894
|
19995
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
20096
| --------- because of this check
@@ -203,7 +99,7 @@ LL | x.unwrap_err(); // will panic
20399
| ^^^^^^^^^^^^^^
204100

205101
error: This call to `unwrap()` will always panic.
206-
--> $DIR/checked_unwrap.rs:72:9
102+
--> $DIR/complex_conditionals.rs:34:9
207103
|
208104
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
209105
| --------- because of this check
@@ -212,7 +108,7 @@ LL | y.unwrap(); // will panic
212108
| ^^^^^^^^^^
213109

214110
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
215-
--> $DIR/checked_unwrap.rs:73:9
111+
--> $DIR/complex_conditionals.rs:35:9
216112
|
217113
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
218114
| --------- the check is happening here
@@ -221,7 +117,7 @@ LL | y.unwrap_err(); // unnecessary
221117
| ^^^^^^^^^^^^^^
222118

223119
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
224-
--> $DIR/checked_unwrap.rs:74:9
120+
--> $DIR/complex_conditionals.rs:36:9
225121
|
226122
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
227123
| ---------- the check is happening here
@@ -230,7 +126,7 @@ LL | z.unwrap(); // unnecessary
230126
| ^^^^^^^^^^
231127

232128
error: This call to `unwrap_err()` will always panic.
233-
--> $DIR/checked_unwrap.rs:75:9
129+
--> $DIR/complex_conditionals.rs:37:9
234130
|
235131
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
236132
| ---------- because of this check
@@ -239,7 +135,7 @@ LL | z.unwrap_err(); // will panic
239135
| ^^^^^^^^^^^^^^
240136

241137
error: This call to `unwrap()` will always panic.
242-
--> $DIR/checked_unwrap.rs:83:9
138+
--> $DIR/complex_conditionals.rs:45:9
243139
|
244140
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
245141
| --------- because of this check
@@ -248,7 +144,7 @@ LL | x.unwrap(); // will panic
248144
| ^^^^^^^^^^
249145

250146
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
251-
--> $DIR/checked_unwrap.rs:84:9
147+
--> $DIR/complex_conditionals.rs:46:9
252148
|
253149
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
254150
| --------- the check is happening here
@@ -257,7 +153,7 @@ LL | x.unwrap_err(); // unnecessary
257153
| ^^^^^^^^^^^^^^
258154

259155
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
260-
--> $DIR/checked_unwrap.rs:85:9
156+
--> $DIR/complex_conditionals.rs:47:9
261157
|
262158
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
263159
| --------- the check is happening here
@@ -266,7 +162,7 @@ LL | y.unwrap(); // unnecessary
266162
| ^^^^^^^^^^
267163

268164
error: This call to `unwrap_err()` will always panic.
269-
--> $DIR/checked_unwrap.rs:86:9
165+
--> $DIR/complex_conditionals.rs:48:9
270166
|
271167
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
272168
| --------- because of this check
@@ -275,7 +171,7 @@ LL | y.unwrap_err(); // will panic
275171
| ^^^^^^^^^^^^^^
276172

277173
error: This call to `unwrap()` will always panic.
278-
--> $DIR/checked_unwrap.rs:87:9
174+
--> $DIR/complex_conditionals.rs:49:9
279175
|
280176
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
281177
| ---------- because of this check
@@ -284,7 +180,7 @@ LL | z.unwrap(); // will panic
284180
| ^^^^^^^^^^
285181

286182
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
287-
--> $DIR/checked_unwrap.rs:88:9
183+
--> $DIR/complex_conditionals.rs:50:9
288184
|
289185
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
290186
| ---------- the check is happening here
@@ -293,21 +189,21 @@ LL | z.unwrap_err(); // unnecessary
293189
| ^^^^^^^^^^^^^^
294190

295191
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
296-
--> $DIR/checked_unwrap.rs:96:13
192+
--> $DIR/complex_conditionals.rs:58:13
297193
|
298194
LL | if x.is_some() {
299195
| ----------- the check is happening here
300196
LL | x.unwrap(); // unnecessary
301197
| ^^^^^^^^^^
302198

303199
error: This call to `unwrap()` will always panic.
304-
--> $DIR/checked_unwrap.rs:98:13
200+
--> $DIR/complex_conditionals.rs:60:13
305201
|
306202
LL | if x.is_some() {
307203
| ----------- because of this check
308204
...
309205
LL | x.unwrap(); // will panic
310206
| ^^^^^^^^^^
311207

312-
error: aborting due to 34 previous errors
208+
error: aborting due to 22 previous errors
313209

0 commit comments

Comments
 (0)