2022-03-01 00:17:45 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None });
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this `.find_map` can be written more simply using `.find`
|
|
|
|
//~| NOTE: `-D clippy::unnecessary-find-map` implied by `-D warnings`
|
2022-03-01 00:17:45 +00:00
|
|
|
let _ = (0..4).find_map(|x| {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this `.find_map` can be written more simply using `.find`
|
2022-03-01 00:17:45 +00:00
|
|
|
if x > 1 {
|
|
|
|
return Some(x);
|
|
|
|
};
|
|
|
|
None
|
|
|
|
});
|
|
|
|
let _ = (0..4).find_map(|x| match x {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this `.find_map` can be written more simply using `.find`
|
2022-03-01 00:17:45 +00:00
|
|
|
0 | 1 => None,
|
|
|
|
_ => Some(x),
|
|
|
|
});
|
|
|
|
|
|
|
|
let _ = (0..4).find_map(|x| Some(x + 1));
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this `.find_map` can be written more simply using `.map(..).next()`
|
2022-03-01 00:17:45 +00:00
|
|
|
|
|
|
|
let _ = (0..4).find_map(i32::checked_abs);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_map_none_changes_item_type() -> Option<bool> {
|
|
|
|
"".chars().find_map(|_| None)
|
|
|
|
}
|
2023-07-30 11:41:58 +00:00
|
|
|
|
|
|
|
fn issue11260() {
|
2023-07-30 14:45:04 +00:00
|
|
|
let y = Some(1);
|
2023-07-30 11:41:58 +00:00
|
|
|
let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
|
2023-07-30 14:45:04 +00:00
|
|
|
let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(y)); // different option, so can't be just `.find()`
|
2023-07-30 11:41:58 +00:00
|
|
|
}
|