rust/tests/ui/unnecessary_literal_unwrap.fixed

79 lines
1.3 KiB
Rust
Raw Normal View History

2023-02-16 17:14:20 -06:00
//@run-rustfix
2023-02-16 08:21:43 -06:00
#![warn(clippy::unnecessary_literal_unwrap)]
2023-02-16 16:31:52 -06:00
#![allow(unreachable_code)]
2023-05-31 14:09:12 -05:00
#![allow(
clippy::unnecessary_lazy_evaluations,
clippy::diverging_sub_expression,
clippy::let_unit_value,
clippy::no_effect
)]
2023-02-16 08:21:43 -06:00
2023-02-16 16:31:52 -06:00
fn unwrap_option_some() {
2023-02-16 08:37:18 -06:00
let _val = 1;
let _val = 1;
2023-05-31 14:09:12 -05:00
1;
1;
2023-02-16 08:37:18 -06:00
}
2023-02-16 16:31:52 -06:00
fn unwrap_option_none() {
2023-05-31 14:09:12 -05:00
let _val = panic!();
let _val = panic!("this always happens");
2023-02-16 16:31:52 -06:00
panic!();
panic!("this always happens");
}
2023-02-16 11:15:19 -06:00
fn unwrap_result_ok() {
let _val = 1;
let _val = 1;
2023-05-31 14:09:12 -05:00
let _val = panic!("{:?}", 1);
let _val = panic!("{1}: {:?}", 1, "this always happens");
1;
1;
2023-02-16 16:31:52 -06:00
panic!("{:?}", 1);
panic!("{1}: {:?}", 1, "this always happens");
2023-02-16 11:15:19 -06:00
}
fn unwrap_result_err() {
2023-02-16 08:37:18 -06:00
let _val = 1;
let _val = 1;
2023-05-31 14:09:12 -05:00
let _val = panic!("{:?}", 1);
let _val = panic!("{1}: {:?}", 1, "this always happens");
1;
1;
2023-02-16 16:31:52 -06:00
panic!("{:?}", 1);
panic!("{1}: {:?}", 1, "this always happens");
2023-02-16 08:21:43 -06:00
}
2023-02-16 08:43:41 -06:00
fn unwrap_methods_option() {
let _val = 1;
let _val = 1;
2023-02-16 09:05:56 -06:00
let _val = 1;
2023-05-31 14:09:12 -05:00
1;
1;
1;
2023-02-16 08:43:41 -06:00
}
fn unwrap_methods_result() {
let _val = 1;
let _val = 1;
2023-02-16 09:05:56 -06:00
let _val = 1;
2023-05-31 14:09:12 -05:00
1;
1;
1;
2023-02-16 08:43:41 -06:00
}
2023-02-16 08:21:43 -06:00
fn main() {
2023-02-16 16:31:52 -06:00
unwrap_option_some();
unwrap_option_none();
2023-02-16 11:15:19 -06:00
unwrap_result_ok();
unwrap_result_err();
2023-02-16 08:43:41 -06:00
unwrap_methods_option();
unwrap_methods_result();
2023-02-16 08:21:43 -06:00
}