]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_map_option.rs
Add: option_manual_map lint
[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     match &mut Some(String::new()) {
70         Some(x) => Some(x.push_str("")),
71         None => None,
72     };
73
74     match &mut Some(String::new()) {
75         Some(ref x) => Some(&**x),
76         None => None,
77     };
78
79     match &mut &Some(String::new()) {
80         Some(x) => Some(x.is_empty()),
81         &mut _ => None,
82     };
83
84     match Some((0, 1, 2)) {
85         Some((x, y, z)) => Some(x + y + z),
86         None => None,
87     };
88
89     match Some([1, 2, 3]) {
90         Some([first, ..]) => Some(first),
91         None => None,
92     };
93
94     match &Some((String::new(), "test")) {
95         Some((x, y)) => Some((y, x)),
96         None => None,
97     };
98
99     match Some((String::new(), 0)) {
100         Some((ref x, y)) => Some((y, x)),
101         None => None,
102     };
103
104     match Some(Some(0)) {
105         Some(Some(_)) | Some(None) => Some(0),
106         None => None,
107     };
108
109     match Some(Some((0, 1))) {
110         Some(Some((x, 1))) => Some(x),
111         _ => None,
112     };
113 }