2021-03-01 16:25:23 -06:00
|
|
|
// edition:2018
|
2021-01-10 08:46:03 -06:00
|
|
|
// run-rustfix
|
|
|
|
|
|
|
|
#![warn(clippy::manual_map)]
|
2021-02-26 10:50:12 -06:00
|
|
|
#![allow(
|
|
|
|
clippy::no_effect,
|
|
|
|
clippy::map_identity,
|
|
|
|
clippy::unit_arg,
|
|
|
|
clippy::match_ref_pats,
|
2021-03-29 19:39:28 -05:00
|
|
|
clippy::redundant_pattern_matching,
|
2021-02-26 10:50:12 -06:00
|
|
|
dead_code
|
|
|
|
)]
|
2021-01-10 08:46:03 -06:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
Some(0).map(|_| 2);
|
|
|
|
|
|
|
|
Some(0).map(|x| x + 1);
|
|
|
|
|
|
|
|
Some("").map(|x| x.is_empty());
|
|
|
|
|
|
|
|
Some(0).map(|x| !x);
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
Some(0).map(std::convert::identity);
|
|
|
|
|
|
|
|
Some(&String::new()).map(|x| str::len(x));
|
|
|
|
|
|
|
|
match Some(0) {
|
|
|
|
Some(x) if false => Some(x + 1),
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
Some([0, 1]).as_ref().map(|x| x[0]);
|
|
|
|
|
|
|
|
Some(0).map(|x| x * 2);
|
|
|
|
|
|
|
|
Some(String::new()).as_ref().map(|x| x.is_empty());
|
|
|
|
|
|
|
|
Some(String::new()).as_ref().map(|x| x.len());
|
|
|
|
|
|
|
|
Some(0).map(|x| x + x);
|
|
|
|
|
2021-02-19 13:04:37 -06:00
|
|
|
#[warn(clippy::option_map_unit_fn)]
|
|
|
|
match &mut Some(String::new()) {
|
|
|
|
Some(x) => Some(x.push_str("")),
|
|
|
|
None => None,
|
|
|
|
};
|
2021-01-10 08:46:03 -06:00
|
|
|
|
2021-02-19 13:04:37 -06:00
|
|
|
#[allow(clippy::option_map_unit_fn)]
|
|
|
|
{
|
|
|
|
Some(String::new()).as_mut().map(|x| x.push_str(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(String::new()).as_ref().map(|x| x.len());
|
2021-01-10 08:46:03 -06:00
|
|
|
|
|
|
|
Some(String::new()).as_ref().map(|x| x.is_empty());
|
|
|
|
|
|
|
|
Some((0, 1, 2)).map(|(x, y, z)| x + y + z);
|
|
|
|
|
|
|
|
Some([1, 2, 3]).map(|[first, ..]| first);
|
|
|
|
|
|
|
|
Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x));
|
|
|
|
|
|
|
|
match Some((String::new(), 0)) {
|
|
|
|
Some((ref x, y)) => Some((y, x)),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
match Some(Some(0)) {
|
|
|
|
Some(Some(_)) | Some(None) => Some(0),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
match Some(Some((0, 1))) {
|
|
|
|
Some(Some((x, 1))) => Some(x),
|
|
|
|
_ => None,
|
|
|
|
};
|
2021-02-26 10:50:12 -06:00
|
|
|
|
|
|
|
// #6795
|
|
|
|
fn f1() -> Result<(), ()> {
|
|
|
|
let _ = match Some(Ok(())) {
|
|
|
|
Some(x) => Some(x?),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
for &x in Some(Some(true)).iter() {
|
|
|
|
let _ = match x {
|
|
|
|
Some(x) => Some(if x { continue } else { x }),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// #6797
|
|
|
|
let x1 = (Some(String::new()), 0);
|
|
|
|
let x2 = x1.0;
|
|
|
|
match x2 {
|
|
|
|
Some(x) => Some((x, x1.1)),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct S1 {
|
|
|
|
x: Option<String>,
|
|
|
|
y: u32,
|
|
|
|
}
|
|
|
|
impl S1 {
|
|
|
|
fn f(self) -> Option<(String, u32)> {
|
|
|
|
match self.x {
|
|
|
|
Some(x) => Some((x, self.y)),
|
|
|
|
None => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 08:03:21 -06:00
|
|
|
|
|
|
|
// #6811
|
|
|
|
Some(0).map(|x| vec![x]);
|
|
|
|
|
|
|
|
option_env!("").map(String::from);
|
2021-03-01 16:25:23 -06:00
|
|
|
|
|
|
|
// #6819
|
|
|
|
async fn f2(x: u32) -> u32 {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn f3() {
|
|
|
|
match Some(0) {
|
|
|
|
Some(x) => Some(f2(x).await),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
}
|
2021-03-05 14:57:37 -06:00
|
|
|
|
|
|
|
// #6847
|
2021-03-29 19:39:28 -05:00
|
|
|
if let Some(_) = Some(0) {
|
|
|
|
Some(0)
|
|
|
|
} else { Some(0).map(|x| x + 1) };
|
|
|
|
|
|
|
|
if true {
|
2021-03-05 14:57:37 -06:00
|
|
|
Some(0)
|
|
|
|
} else { Some(0).map(|x| x + 1) };
|
2021-03-25 21:48:27 -05:00
|
|
|
|
|
|
|
// #6967
|
|
|
|
const fn f4() {
|
|
|
|
match Some(0) {
|
|
|
|
Some(x) => Some(x + 1),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
}
|
2021-01-10 08:46:03 -06:00
|
|
|
}
|