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