2021-08-01 22:39:56 +00:00
|
|
|
#![warn(clippy::manual_map)]
|
2021-08-09 18:18:53 +00:00
|
|
|
#![allow(clippy::toplevel_ref_arg)]
|
2021-08-01 22:39:56 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-08-09 18:18:53 +00:00
|
|
|
// Lint. `y` is declared within the arm, so it isn't captured by the map closure
|
2021-08-01 22:39:56 +00:00
|
|
|
let _ = Some(0).map(|x| {
|
|
|
|
let y = (String::new(), String::new());
|
|
|
|
(x, y.0)
|
|
|
|
});
|
2021-08-04 17:48:45 +00:00
|
|
|
|
2021-08-09 18:18:53 +00:00
|
|
|
// Don't lint. `s` is borrowed until partway through the arm, but needs to be captured by the map
|
|
|
|
// closure
|
2021-08-04 17:48:45 +00:00
|
|
|
let s = Some(String::new());
|
|
|
|
let _ = match &s {
|
|
|
|
Some(x) => Some((x.clone(), s)),
|
|
|
|
None => None,
|
|
|
|
};
|
2021-08-09 18:18:53 +00:00
|
|
|
|
|
|
|
// 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!() }
|
|
|
|
});
|
2021-11-13 00:12:17 +00:00
|
|
|
|
2021-11-17 15:39:53 +00:00
|
|
|
// Issue #7820
|
2021-11-13 00:12:17 +00:00
|
|
|
unsafe fn f(x: u32) -> u32 {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
unsafe {
|
|
|
|
let _ = Some(0).map(|x| f(x));
|
|
|
|
}
|
|
|
|
let _ = Some(0).map(|x| unsafe { f(x) });
|
2021-11-17 15:39:53 +00:00
|
|
|
let _ = Some(0).map(|x| unsafe { f(x) });
|
2021-08-01 22:39:56 +00:00
|
|
|
}
|