]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_map_option_2.rs
0862b201ead4b7290f600e6b27454a8a1b72dc4a
[rust.git] / tests / ui / manual_map_option_2.rs
1 // run-rustfix
2
3 #![warn(clippy::manual_map)]
4 #![allow(clippy::toplevel_ref_arg)]
5
6 fn main() {
7     // Lint. `y` is declared within the arm, so it isn't captured by the map closure
8     let _ = match Some(0) {
9         Some(x) => Some({
10             let y = (String::new(), String::new());
11             (x, y.0)
12         }),
13         None => None,
14     };
15
16     // Don't lint. `s` is borrowed until partway through the arm, but needs to be captured by the map
17     // closure
18     let s = Some(String::new());
19     let _ = match &s {
20         Some(x) => Some((x.clone(), s)),
21         None => None,
22     };
23
24     // Don't lint. `s` is borrowed until partway through the arm, but needs to be captured by the map
25     // closure
26     let s = Some(String::new());
27     let _ = match &s {
28         Some(x) => Some({
29             let clone = x.clone();
30             let s = || s;
31             (clone, s())
32         }),
33         None => None,
34     };
35
36     // Don't lint. `s` is borrowed until partway through the arm, but needs to be captured as a mutable
37     // reference by the map closure
38     let mut s = Some(String::new());
39     let _ = match &s {
40         Some(x) => Some({
41             let clone = x.clone();
42             let ref mut s = s;
43             (clone, s)
44         }),
45         None => None,
46     };
47
48     // Lint. `s` is captured by reference, so no lifetime issues.
49     let s = Some(String::new());
50     let _ = match &s {
51         Some(x) => Some({
52             if let Some(ref s) = s { (x.clone(), s) } else { panic!() }
53         }),
54         None => None,
55     };
56 }