]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/entry_with_else.fixed
Rollup merge of #99474 - aDotInTheVoid:rustdoc-json-noinline-test-cleanup, r=CraftSpider
[rust.git] / src / tools / clippy / tests / ui / entry_with_else.fixed
1 // run-rustfix
2
3 #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
4 #![warn(clippy::map_entry)]
5
6 use std::collections::{BTreeMap, HashMap};
7 use std::hash::Hash;
8
9 macro_rules! m {
10     ($e:expr) => {{ $e }};
11 }
12
13 fn foo() {}
14
15 fn insert_if_absent0<K: Eq + Hash + Copy, V: Copy>(m: &mut HashMap<K, V>, k: K, v: V, v2: V) {
16     match m.entry(k) {
17         std::collections::hash_map::Entry::Vacant(e) => {
18             e.insert(v);
19         }
20         std::collections::hash_map::Entry::Occupied(mut e) => {
21             e.insert(v2);
22         }
23     }
24
25     match m.entry(k) {
26         std::collections::hash_map::Entry::Occupied(mut e) => {
27             e.insert(v);
28         }
29         std::collections::hash_map::Entry::Vacant(e) => {
30             e.insert(v2);
31         }
32     }
33
34     if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
35         e.insert(v);
36     } else {
37         foo();
38     }
39
40     if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) {
41         e.insert(v);
42     } else {
43         foo();
44     }
45
46     match m.entry(k) {
47         std::collections::hash_map::Entry::Vacant(e) => {
48             e.insert(v);
49         }
50         std::collections::hash_map::Entry::Occupied(mut e) => {
51             e.insert(v2);
52         }
53     }
54
55     match m.entry(k) {
56         std::collections::hash_map::Entry::Occupied(mut e) => {
57             if true { Some(e.insert(v)) } else { Some(e.insert(v2)) }
58         }
59         std::collections::hash_map::Entry::Vacant(e) => {
60             e.insert(v);
61             None
62         }
63     };
64
65     if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) {
66         foo();
67         Some(e.insert(v))
68     } else {
69         None
70     };
71 }
72
73 fn main() {}