]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs
Auto merge of #79780 - camelid:use-summary_opts, r=GuillaumeGomez
[rust.git] / src / tools / clippy / tests / ui / redundant_pattern_matching_option.rs
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 let None = None::<()> {}
9
10     if let Some(_) = Some(42) {}
11
12     if let Some(_) = Some(42) {
13         foo();
14     } else {
15         bar();
16     }
17
18     while let Some(_) = Some(42) {}
19
20     while let None = Some(42) {}
21
22     while let None = None::<()> {}
23
24     let mut v = vec![1, 2, 3];
25     while let Some(_) = v.pop() {
26         foo();
27     }
28
29     if None::<i32>.is_none() {}
30
31     if Some(42).is_some() {}
32
33     match Some(42) {
34         Some(_) => true,
35         None => false,
36     };
37
38     match None::<()> {
39         Some(_) => false,
40         None => true,
41     };
42
43     let _ = match None::<()> {
44         Some(_) => false,
45         None => true,
46     };
47
48     let opt = Some(false);
49     let _ = if let Some(_) = opt { true } else { false };
50
51     issue6067();
52
53     let _ = if let Some(_) = gen_opt() {
54         1
55     } else if let None = gen_opt() {
56         2
57     } else {
58         3
59     };
60 }
61
62 fn gen_opt() -> Option<()> {
63     None
64 }
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 let Some(_) = Some(42) {}
75
76     if let None = None::<()> {}
77
78     while let Some(_) = Some(42) {}
79
80     while let None = None::<()> {}
81
82     match Some(42) {
83         Some(_) => true,
84         None => false,
85     };
86
87     match None::<()> {
88         Some(_) => false,
89         None => true,
90     };
91 }