rust-clippy/tests/ui/unnecessary_literal_unwrap.fixed

50 lines
900 B
Rust
Raw Normal View History

2023-02-16 23:14:20 +00:00
//@run-rustfix
2023-02-16 14:21:43 +00:00
#![warn(clippy::unnecessary_literal_unwrap)]
2023-02-16 22:31:52 +00:00
#![allow(unreachable_code)]
2023-02-16 23:14:20 +00:00
#![allow(clippy::unnecessary_lazy_evaluations)]
2023-02-16 14:21:43 +00:00
2023-02-16 22:31:52 +00:00
fn unwrap_option_some() {
2023-02-16 14:37:18 +00:00
let _val = 1;
let _val = 1;
}
2023-02-16 22:31:52 +00:00
fn unwrap_option_none() {
panic!();
panic!("this always happens");
}
2023-02-16 17:15:19 +00:00
fn unwrap_result_ok() {
let _val = 1;
let _val = 1;
2023-02-16 22:31:52 +00:00
panic!("{:?}", 1);
panic!("{1}: {:?}", 1, "this always happens");
2023-02-16 17:15:19 +00:00
}
fn unwrap_result_err() {
2023-02-16 14:37:18 +00:00
let _val = 1;
let _val = 1;
2023-02-16 22:31:52 +00:00
panic!("{:?}", 1);
panic!("{1}: {:?}", 1, "this always happens");
2023-02-16 14:21:43 +00:00
}
2023-02-16 14:43:41 +00:00
fn unwrap_methods_option() {
let _val = 1;
let _val = 1;
2023-02-16 15:05:56 +00:00
let _val = 1;
2023-02-16 14:43:41 +00:00
}
fn unwrap_methods_result() {
let _val = 1;
let _val = 1;
2023-02-16 15:05:56 +00:00
let _val = 1;
2023-02-16 14:43:41 +00:00
}
2023-02-16 14:21:43 +00:00
fn main() {
2023-02-16 22:31:52 +00:00
unwrap_option_some();
unwrap_option_none();
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 14:21:43 +00:00
}