fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.0 KiB109 linesraw
1#![warn(clippy::unnecessary_literal_unwrap)]
2#![allow(unreachable_code)]
3#![allow(
4    clippy::unnecessary_lazy_evaluations,
5    clippy::diverging_sub_expression,
6    clippy::let_unit_value,
7    clippy::no_effect
8)]
9
10fn unwrap_option_some() {
11    let _val = 1;
12    let _val = 1;
13
14    1;
15    1;
16}
17
18#[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }`
19fn unwrap_option_none() {
20    let _val = panic!();
21    let _val = panic!("this always happens");
22    let _val: String = String::default();
23    let _val: u16 = 234;
24    let _val: u16 = 234;
25    let _val: u16 = { 234 };
26    let _val: u16 = { 234 };
27
28    panic!();
29    panic!("this always happens");
30    String::default();
31    234;
32    234;
33    { 234 };
34    { 234 };
35}
36
37fn unwrap_result_ok() {
38    let _val = 1;
39    let _val = 1;
40    let _val = panic!("{:?}", 1);
41    let _val = panic!("{1}: {:?}", 1, "this always happens");
42
43    1;
44    1;
45    panic!("{:?}", 1);
46    panic!("{1}: {:?}", 1, "this always happens");
47}
48
49fn unwrap_result_err() {
50    let _val = 1;
51    let _val = 1;
52    let _val = panic!("{:?}", 1);
53    let _val = panic!("{1}: {:?}", 1, "this always happens");
54
55    1;
56    1;
57    panic!("{:?}", 1);
58    panic!("{1}: {:?}", 1, "this always happens");
59}
60
61fn unwrap_methods_option() {
62    let _val = 1;
63    let _val = 1;
64    let _val = 1;
65
66    1;
67    1;
68    1;
69}
70
71fn unwrap_methods_result() {
72    let _val = 1;
73    let _val = 1;
74    let _val = 1;
75
76    1;
77    1;
78    1;
79}
80
81fn unwrap_from_binding() {
82    macro_rules! from_macro {
83        () => {
84            Some("")
85        };
86    }
87    let val = from_macro!();
88    let _ = val.unwrap_or("");
89}
90
91fn unwrap_unchecked() {
92    let _ = 1;
93    let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block
94    let _ = 1 + 1;
95    let _ = 1;
96    let _ = unsafe { 1 + *(&1 as *const i32) };
97    let _ = 1 + 1;
98    let _ = 123;
99}
100
101fn main() {
102    unwrap_option_some();
103    unwrap_option_none();
104    unwrap_result_ok();
105    unwrap_result_err();
106    unwrap_methods_option();
107    unwrap_methods_result();
108    unwrap_unchecked();
109}