2023-02-16 14:21:43 +00:00
|
|
|
//run-rustfix
|
2023-02-16 11:32:12 +00:00
|
|
|
#![warn(clippy::unnecessary_literal_unwrap)]
|
2023-02-16 15:05:56 +00:00
|
|
|
#![allow(clippy::unnecessary_lazy_evaluations)]
|
2023-02-16 11:32:12 +00:00
|
|
|
|
|
|
|
fn unwrap_option() {
|
2023-02-16 14:37:18 +00:00
|
|
|
let _val = Some(1).unwrap();
|
|
|
|
let _val = Some(1).expect("this never happens");
|
|
|
|
}
|
|
|
|
|
2023-02-16 17:15:19 +00:00
|
|
|
fn unwrap_result_ok() {
|
2023-02-16 14:37:18 +00:00
|
|
|
let _val = Ok::<usize, ()>(1).unwrap();
|
|
|
|
let _val = Ok::<usize, ()>(1).expect("this never happens");
|
2023-02-16 17:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn unwrap_result_err() {
|
|
|
|
let _val = Err::<(), usize>(1).unwrap_err();
|
|
|
|
let _val = Err::<(), usize>(1).expect_err("this never happens");
|
2023-02-16 11:32:12 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 14:43:41 +00:00
|
|
|
fn unwrap_methods_option() {
|
|
|
|
let _val = Some(1).unwrap_or(2);
|
|
|
|
let _val = Some(1).unwrap_or_default();
|
2023-02-16 15:05:56 +00:00
|
|
|
let _val = Some(1).unwrap_or_else(|| _val);
|
2023-02-16 14:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn unwrap_methods_result() {
|
|
|
|
let _val = Ok::<usize, ()>(1).unwrap_or(2);
|
|
|
|
let _val = Ok::<usize, ()>(1).unwrap_or_default();
|
2023-02-16 15:05:56 +00:00
|
|
|
let _val = Ok::<usize, ()>(1).unwrap_or_else(|()| _val);
|
2023-02-16 14:43:41 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 11:32:12 +00:00
|
|
|
fn main() {
|
|
|
|
unwrap_option();
|
2023-02-16 17:15:19 +00:00
|
|
|
unwrap_result_ok();
|
|
|
|
unwrap_result_err();
|
2023-02-16 14:43:41 +00:00
|
|
|
unwrap_methods_option();
|
|
|
|
unwrap_methods_result();
|
2023-02-16 11:32:12 +00:00
|
|
|
}
|