1 #![warn(clippy::unwrap_used, clippy::expect_used)] 2 #![allow(clippy::unnecessary_literal_unwrap)] 3 4 trait OptionExt { 5 type Item; 6 unwrap_err(self) -> Self::Item7 fn unwrap_err(self) -> Self::Item; 8 expect_err(self, msg: &str) -> Self::Item9 fn expect_err(self, msg: &str) -> Self::Item; 10 } 11 12 impl<T> OptionExt for Option<T> { 13 type Item = T; unwrap_err(self) -> T14 fn unwrap_err(self) -> T { 15 panic!(); 16 } 17 expect_err(self, msg: &str) -> T18 fn expect_err(self, msg: &str) -> T { 19 panic!(); 20 } 21 } 22 main()23fn main() { 24 Some(3).unwrap(); 25 Some(3).expect("Hello world!"); 26 27 // Don't trigger on unwrap_err on an option 28 Some(3).unwrap_err(); 29 Some(3).expect_err("Hellow none!"); 30 31 let a: Result<i32, i32> = Ok(3); 32 a.unwrap(); 33 a.expect("Hello world!"); 34 a.unwrap_err(); 35 a.expect_err("Hello error!"); 36 } 37