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