]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] |
2 | #![allow(clippy::if_same_then_else)] | |
3 | ||
4 | fn test_complex_conditions() { | |
5 | let x: Result<(), ()> = Ok(()); | |
6 | let y: Result<(), ()> = Ok(()); | |
7 | if x.is_ok() && y.is_err() { | |
8 | x.unwrap(); // unnecessary | |
9 | x.unwrap_err(); // will panic | |
10 | y.unwrap(); // will panic | |
11 | y.unwrap_err(); // unnecessary | |
12 | } else { | |
13 | // not statically determinable whether any of the following will always succeed or always fail: | |
14 | x.unwrap(); | |
15 | x.unwrap_err(); | |
16 | y.unwrap(); | |
17 | y.unwrap_err(); | |
18 | } | |
19 | ||
20 | if x.is_ok() || y.is_ok() { | |
21 | // not statically determinable whether any of the following will always succeed or always fail: | |
22 | x.unwrap(); | |
23 | y.unwrap(); | |
24 | } else { | |
25 | x.unwrap(); // will panic | |
26 | x.unwrap_err(); // unnecessary | |
27 | y.unwrap(); // will panic | |
28 | y.unwrap_err(); // unnecessary | |
29 | } | |
30 | let z: Result<(), ()> = Ok(()); | |
31 | if x.is_ok() && !(y.is_ok() || z.is_err()) { | |
32 | x.unwrap(); // unnecessary | |
33 | x.unwrap_err(); // will panic | |
34 | y.unwrap(); // will panic | |
35 | y.unwrap_err(); // unnecessary | |
36 | z.unwrap(); // unnecessary | |
37 | z.unwrap_err(); // will panic | |
38 | } | |
39 | if x.is_ok() || !(y.is_ok() && z.is_err()) { | |
40 | // not statically determinable whether any of the following will always succeed or always fail: | |
41 | x.unwrap(); | |
42 | y.unwrap(); | |
43 | z.unwrap(); | |
44 | } else { | |
45 | x.unwrap(); // will panic | |
46 | x.unwrap_err(); // unnecessary | |
47 | y.unwrap(); // unnecessary | |
48 | y.unwrap_err(); // will panic | |
49 | z.unwrap(); // will panic | |
50 | z.unwrap_err(); // unnecessary | |
51 | } | |
52 | } | |
53 | ||
54 | fn main() {} |