rust-clippy/tests/ui/find_map.rs

35 lines
854 B
Rust
Raw Normal View History

2019-04-27 22:06:35 +00:00
#![warn(clippy::all, clippy::pedantic)]
2023-06-06 20:56:57 +00:00
#![allow(clippy::useless_vec)]
2019-04-27 22:06:35 +00:00
#[derive(Debug, Copy, Clone)]
enum Flavor {
Chocolate,
}
#[derive(Debug, Copy, Clone)]
enum Dessert {
Banana,
Pudding,
Cake(Flavor),
}
fn main() {
let desserts_of_the_week = vec![Dessert::Banana, Dessert::Cake(Flavor::Chocolate), Dessert::Pudding];
let a = ["lol", "NaN", "2", "5", "Xunda"];
let _: Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok()).map(|s| s.parse().unwrap());
2020-07-05 20:10:59 +00:00
#[allow(clippy::match_like_matches_macro)]
2019-04-27 22:06:35 +00:00
let _: Option<Flavor> = desserts_of_the_week
.iter()
.find(|dessert| match *dessert {
Dessert::Cake(_) => true,
_ => false,
})
.map(|dessert| match *dessert {
Dessert::Cake(ref flavor) => *flavor,
_ => unreachable!(),
});
}