1 // run-rustfix
2
3 #![warn(clippy::all)]
4 #![warn(clippy::redundant_pattern_matching)]
5 #![allow(
6 unused_must_use,
7 clippy::needless_bool,
8 clippy::match_like_matches_macro,
9 clippy::equatable_if_let,
10 clippy::if_same_then_else
11 )]
12
main()13 fn main() {
14 if let None = None::<()> {}
15
16 if let Some(_) = Some(42) {}
17
18 if let Some(_) = Some(42) {
19 foo();
20 } else {
21 bar();
22 }
23
24 while let Some(_) = Some(42) {}
25
26 while let None = Some(42) {}
27
28 while let None = None::<()> {}
29
30 let mut v = vec![1, 2, 3];
31 while let Some(_) = v.pop() {
32 foo();
33 }
34
35 if None::<i32>.is_none() {}
36
37 if Some(42).is_some() {}
38
39 match Some(42) {
40 Some(_) => true,
41 None => false,
42 };
43
44 match None::<()> {
45 Some(_) => false,
46 None => true,
47 };
48
49 let _ = match None::<()> {
50 Some(_) => false,
51 None => true,
52 };
53
54 let opt = Some(false);
55 let _ = if let Some(_) = opt { true } else { false };
56
57 issue6067();
58
59 let _ = if let Some(_) = gen_opt() {
60 1
61 } else if let None = gen_opt() {
62 2
63 } else {
64 3
65 };
66 }
67
gen_opt() -> Option<()>68 fn gen_opt() -> Option<()> {
69 None
70 }
71
foo()72 fn foo() {}
73
bar()74 fn bar() {}
75
76 // Methods that are unstable const should not be suggested within a const context, see issue #5697.
77 // However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const,
78 // so the following should be linted.
issue6067()79 const fn issue6067() {
80 if let Some(_) = Some(42) {}
81
82 if let None = None::<()> {}
83
84 while let Some(_) = Some(42) {}
85
86 while let None = None::<()> {}
87
88 match Some(42) {
89 Some(_) => true,
90 None => false,
91 };
92
93 match None::<()> {
94 Some(_) => false,
95 None => true,
96 };
97 }
98