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