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