1 #![feature(lint_reasons)]
2 #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
3 #![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
8 $a.unwrap(); // unnecessary
13 macro_rules! checks_in_param {
14 ($a:expr, $b:expr) => {
21 macro_rules! checks_unwrap {
22 ($a:expr, $b:expr) => {
29 macro_rules! checks_some {
30 ($a:expr, $b:expr) => {
40 x.unwrap(); // unnecessary
41 x.expect("an error message"); // unnecessary
43 x.unwrap(); // will panic
44 x.expect("an error message"); // will panic
47 x.unwrap(); // will panic
49 x.unwrap(); // unnecessary
52 checks_in_param!(x.is_some(), x.unwrap()); // ok
53 checks_unwrap!(x, x.unwrap()); // ok
54 checks_some!(x.is_some(), x); // ok
55 let mut x: Result<(), ()> = Ok(());
57 x.unwrap(); // unnecessary
58 x.expect("an error message"); // unnecessary
59 x.unwrap_err(); // will panic
61 x.unwrap(); // will panic
62 x.expect("an error message"); // will panic
63 x.unwrap_err(); // unnecessary
66 x.unwrap(); // will panic
67 x.unwrap_err(); // unnecessary
69 x.unwrap(); // unnecessary
70 x.unwrap_err(); // will panic
74 // not unnecessary because of mutation of x
75 // it will always panic but the lint is not smart enough to see this (it only
76 // checks if conditions).
80 // not unnecessary because of mutation of x
81 // it will always panic but the lint is not smart enough to see this (it
82 // only checks if conditions).
86 assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern
92 #[expect(clippy::unnecessary_unwrap)]
93 x.unwrap(); // unnecessary
94 #[expect(clippy::unnecessary_unwrap)]
95 x.expect("an error message"); // unnecessary
97 #[expect(clippy::panicking_unwrap)]
98 x.unwrap(); // will panic
99 #[expect(clippy::panicking_unwrap)]
100 x.expect("an error message"); // will panic