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