Skip to content

Commit a808779

Browse files
committed
Split up checked_unwrap test further
1 parent c7c7ab2 commit a808779

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

tests/ui/checked_unwrap/complex_conditionals.rs

-11
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,4 @@ fn test_complex_conditions() {
5151
}
5252
}
5353

54-
fn test_nested() {
55-
fn nested() {
56-
let x = Some(());
57-
if x.is_some() {
58-
x.unwrap(); // unnecessary
59-
} else {
60-
x.unwrap(); // will panic
61-
}
62-
}
63-
}
64-
6554
fn main() {}

tests/ui/checked_unwrap/complex_conditionals.stderr

+1-18
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,5 @@ LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
188188
LL | z.unwrap_err(); // unnecessary
189189
| ^^^^^^^^^^^^^^
190190

191-
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
192-
--> $DIR/complex_conditionals.rs:58:13
193-
|
194-
LL | if x.is_some() {
195-
| ----------- the check is happening here
196-
LL | x.unwrap(); // unnecessary
197-
| ^^^^^^^^^^
198-
199-
error: This call to `unwrap()` will always panic.
200-
--> $DIR/complex_conditionals.rs:60:13
201-
|
202-
LL | if x.is_some() {
203-
| ----------- because of this check
204-
...
205-
LL | x.unwrap(); // will panic
206-
| ^^^^^^^^^^
207-
208-
error: aborting due to 22 previous errors
191+
error: aborting due to 20 previous errors
209192

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
2+
#![allow(clippy::if_same_then_else)]
3+
4+
fn test_nested() {
5+
fn nested() {
6+
let x = Some(());
7+
if x.is_some() {
8+
x.unwrap(); // unnecessary
9+
} else {
10+
x.unwrap(); // will panic
11+
}
12+
}
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
2+
--> $DIR/complex_conditionals_nested.rs:8:13
3+
|
4+
LL | if x.is_some() {
5+
| ----------- the check is happening here
6+
LL | x.unwrap(); // unnecessary
7+
| ^^^^^^^^^^
8+
|
9+
note: the lint level is defined here
10+
--> $DIR/complex_conditionals_nested.rs:1:35
11+
|
12+
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: This call to `unwrap()` will always panic.
16+
--> $DIR/complex_conditionals_nested.rs:10:13
17+
|
18+
LL | if x.is_some() {
19+
| ----------- because of this check
20+
...
21+
LL | x.unwrap(); // will panic
22+
| ^^^^^^^^^^
23+
|
24+
note: the lint level is defined here
25+
--> $DIR/complex_conditionals_nested.rs:1:9
26+
|
27+
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^
29+
30+
error: aborting due to 2 previous errors
31+

0 commit comments

Comments
 (0)