summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/find_map.rs
blob: 88d3b0e74900152d33938bf332da60dd9035f31c (plain)
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
#![warn(clippy::all, clippy::pedantic)]

#[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());

    #[allow(clippy::match_like_matches_macro)]
    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!(),
        });
}