]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_map_option.rs
Fix dogfood errors
[rust.git] / tests / ui / manual_map_option.rs
1 // run-rustfix
2
3 #![warn(clippy::manual_map)]
4 #![allow(clippy::no_effect, clippy::map_identity, clippy::unit_arg, clippy::match_ref_pats)]
5
6 fn main() {
7     match Some(0) {
8         Some(_) => Some(2),
9         None::<u32> => None,
10     };
11
12     match Some(0) {
13         Some(x) => Some(x + 1),
14         _ => None,
15     };
16
17     match Some("") {
18         Some(x) => Some(x.is_empty()),
19         None => None,
20     };
21
22     if let Some(x) = Some(0) {
23         Some(!x)
24     } else {
25         None
26     };
27
28     #[rustfmt::skip]
29     match Some(0) {
30         Some(x) => { Some(std::convert::identity(x)) }
31         None => { None }
32     };
33
34     match Some(&String::new()) {
35         Some(x) => Some(str::len(x)),
36         None => None,
37     };
38
39     match Some(0) {
40         Some(x) if false => Some(x + 1),
41         _ => None,
42     };
43
44     match &Some([0, 1]) {
45         Some(x) => Some(x[0]),
46         &None => None,
47     };
48
49     match &Some(0) {
50         &Some(x) => Some(x * 2),
51         None => None,
52     };
53
54     match Some(String::new()) {
55         Some(ref x) => Some(x.is_empty()),
56         _ => None,
57     };
58
59     match &&Some(String::new()) {
60         Some(x) => Some(x.len()),
61         _ => None,
62     };
63
64     match &&Some(0) {
65         &&Some(x) => Some(x + x),
66         &&_ => None,
67     };
68
69     #[warn(clippy::option_map_unit_fn)]
70     match &mut Some(String::new()) {
71         Some(x) => Some(x.push_str("")),
72         None => None,
73     };
74
75     #[allow(clippy::option_map_unit_fn)]
76     {
77         match &mut Some(String::new()) {
78             Some(x) => Some(x.push_str("")),
79             None => None,
80         };
81     }
82
83     match &mut Some(String::new()) {
84         Some(ref x) => Some(x.len()),
85         None => None,
86     };
87
88     match &mut &Some(String::new()) {
89         Some(x) => Some(x.is_empty()),
90         &mut _ => None,
91     };
92
93     match Some((0, 1, 2)) {
94         Some((x, y, z)) => Some(x + y + z),
95         None => None,
96     };
97
98     match Some([1, 2, 3]) {
99         Some([first, ..]) => Some(first),
100         None => None,
101     };
102
103     match &Some((String::new(), "test")) {
104         Some((x, y)) => Some((y, x)),
105         None => None,
106     };
107
108     match Some((String::new(), 0)) {
109         Some((ref x, y)) => Some((y, x)),
110         None => None,
111     };
112
113     match Some(Some(0)) {
114         Some(Some(_)) | Some(None) => Some(0),
115         None => None,
116     };
117
118     match Some(Some((0, 1))) {
119         Some(Some((x, 1))) => Some(x),
120         _ => None,
121     };
122 }