1 #![feature(tool_lints)]
3 #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
4 #![allow(clippy::if_same_then_else)]
9 x.unwrap(); // unnecessary
11 x.unwrap(); // will panic
14 x.unwrap(); // will panic
16 x.unwrap(); // unnecessary
18 let mut x: Result<(), ()> = Ok(());
20 x.unwrap(); // unnecessary
21 x.unwrap_err(); // will panic
23 x.unwrap(); // will panic
24 x.unwrap_err(); // unnecessary
27 x.unwrap(); // will panic
28 x.unwrap_err(); // unnecessary
30 x.unwrap(); // unnecessary
31 x.unwrap_err(); // will panic
35 x.unwrap(); // not unnecessary because of mutation of x
36 // it will always panic but the lint is not smart enough to see this (it only checks if conditions).
39 x.unwrap_err(); // not unnecessary because of mutation of x
40 // it will always panic but the lint is not smart enough to see this (it only checks if conditions).
44 fn test_complex_conditions() {
45 let x: Result<(), ()> = Ok(());
46 let y: Result<(), ()> = Ok(());
47 if x.is_ok() && y.is_err() {
48 x.unwrap(); // unnecessary
49 x.unwrap_err(); // will panic
50 y.unwrap(); // will panic
51 y.unwrap_err(); // unnecessary
53 // not statically determinable whether any of the following will always succeed or always fail:
60 if x.is_ok() || y.is_ok() {
61 // not statically determinable whether any of the following will always succeed or always fail:
65 x.unwrap(); // will panic
66 x.unwrap_err(); // unnecessary
67 y.unwrap(); // will panic
68 y.unwrap_err(); // unnecessary
70 let z: Result<(), ()> = Ok(());
71 if x.is_ok() && !(y.is_ok() || z.is_err()) {
72 x.unwrap(); // unnecessary
73 x.unwrap_err(); // will panic
74 y.unwrap(); // will panic
75 y.unwrap_err(); // unnecessary
76 z.unwrap(); // unnecessary
77 z.unwrap_err(); // will panic
79 if x.is_ok() || !(y.is_ok() && z.is_err()) {
80 // not statically determinable whether any of the following will always succeed or always fail:
85 x.unwrap(); // will panic
86 x.unwrap_err(); // unnecessary
87 y.unwrap(); // unnecessary
88 y.unwrap_err(); // will panic
89 z.unwrap(); // will panic
90 z.unwrap_err(); // unnecessary
98 x.unwrap(); // unnecessary
100 x.unwrap(); // will panic