summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/entry_with_else.fixed
blob: 34804b9ee5d77325b0d9e9d26db2409683d9b8b1 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
#![warn(clippy::map_entry)]

use std::collections::{BTreeMap, HashMap};
use std::hash::Hash;

macro_rules! m {
    ($e:expr) => {{ $e }};
}

fn foo() {}

fn insert_if_absent0<K: Eq + Hash + Copy, V: Copy>(m: &mut HashMap<K, V>, k: K, v: V, v2: V) {
    match m.entry(k) {
        std::collections::hash_map::Entry::Vacant(e) => {
            e.insert(v);
        }
        std::collections::hash_map::Entry::Occupied(mut e) => {
            e.insert(v2);
        }
    }

    match m.entry(k) {
        std::collections::hash_map::Entry::Occupied(mut e) => {
            e.insert(v);
        }
        std::collections::hash_map::Entry::Vacant(e) => {
            e.insert(v2);
        }
    }

    if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
        e.insert(v);
    } else {
        foo();
    }

    if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) {
        e.insert(v);
    } else {
        foo();
    }

    match m.entry(k) {
        std::collections::hash_map::Entry::Vacant(e) => {
            e.insert(v);
        }
        std::collections::hash_map::Entry::Occupied(mut e) => {
            e.insert(v2);
        }
    }

    match m.entry(k) {
        std::collections::hash_map::Entry::Occupied(mut e) => {
            if true { Some(e.insert(v)) } else { Some(e.insert(v2)) }
        }
        std::collections::hash_map::Entry::Vacant(e) => {
            e.insert(v);
            None
        }
    };

    if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) {
        foo();
        Some(e.insert(v))
    } else {
        None
    };
}

fn main() {}