1 #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
2 #![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
7 $a.unwrap(); // unnecessary
12 macro_rules! checks_in_param {
13 ($a:expr, $b:expr) => {
20 macro_rules! checks_unwrap {
21 ($a:expr, $b:expr) => {
28 macro_rules! checks_some {
29 ($a:expr, $b:expr) => {
39 x.unwrap(); // unnecessary
40 x.expect("an error message"); // unnecessary
42 x.unwrap(); // will panic
43 x.expect("an error message"); // will panic
46 x.unwrap(); // will panic
48 x.unwrap(); // unnecessary
51 checks_in_param!(x.is_some(), x.unwrap()); // ok
52 checks_unwrap!(x, x.unwrap()); // ok
53 checks_some!(x.is_some(), x); // ok
54 let mut x: Result<(), ()> = Ok(());
56 x.unwrap(); // unnecessary
57 x.expect("an error message"); // unnecessary
58 x.unwrap_err(); // will panic
60 x.unwrap(); // will panic
61 x.expect("an error message"); // will panic
62 x.unwrap_err(); // unnecessary
65 x.unwrap(); // will panic
66 x.unwrap_err(); // unnecessary
68 x.unwrap(); // unnecessary
69 x.unwrap_err(); // will panic
73 // not unnecessary because of mutation of x
74 // it will always panic but the lint is not smart enough to see this (it only
75 // checks if conditions).
79 // not unnecessary because of mutation of x
80 // it will always panic but the lint is not smart enough to see this (it
81 // only checks if conditions).
85 assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern