]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
New upstream version 1.53.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / redundant_pattern_matching_option.fixed
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::if_same_then_else
10 )]
11
12 fn main() {
13 if None::<()>.is_none() {}
14
15 if Some(42).is_some() {}
16
17 if Some(42).is_some() {
18 foo();
19 } else {
20 bar();
21 }
22
23 while Some(42).is_some() {}
24
25 while Some(42).is_none() {}
26
27 while None::<()>.is_none() {}
28
29 let mut v = vec![1, 2, 3];
30 while v.pop().is_some() {
31 foo();
32 }
33
34 if None::<i32>.is_none() {}
35
36 if Some(42).is_some() {}
37
38 Some(42).is_some();
39
40 None::<()>.is_none();
41
42 let _ = None::<()>.is_none();
43
44 let opt = Some(false);
45 let _ = if opt.is_some() { true } else { false };
46
47 issue6067();
48
49 let _ = if gen_opt().is_some() {
50 1
51 } else if gen_opt().is_none() {
52 2
53 } else {
54 3
55 };
56 }
57
58 fn gen_opt() -> Option<()> {
59 None
60 }
61
62 fn foo() {}
63
64 fn bar() {}
65
66 // Methods that are unstable const should not be suggested within a const context, see issue #5697.
67 // However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const,
68 // so the following should be linted.
69 const fn issue6067() {
70 if Some(42).is_some() {}
71
72 if None::<()>.is_none() {}
73
74 while Some(42).is_some() {}
75
76 while None::<()>.is_none() {}
77
78 Some(42).is_some();
79
80 None::<()>.is_none();
81 }