3 #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
4 #![warn(clippy::map_entry)]
7 use std::collections::HashMap;
11 ($e:expr) => {{ $e }};
15 ($map:expr, $key:expr, $val:expr) => {
16 $map.insert($key, $val)
22 fn hash_map<K: Eq + Hash + Copy, V: Copy>(m: &mut HashMap<K, V>, m2: &mut HashMap<K, V>, k: K, k2: K, v: V, v2: V) {
24 m.entry(k).or_insert(v);
26 // semicolon on insert, use or_insert_with(..)
27 m.entry(k).or_insert_with(|| {
35 // semicolon on if, use or_insert_with(..)
36 m.entry(k).or_insert_with(|| {
44 // early return, use if let
45 if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
54 // use or_insert_with(..)
55 m.entry(k).or_insert_with(|| {
60 // semicolon on insert and match, use or_insert_with(..)
61 m.entry(k).or_insert_with(|| {
72 // one branch doesn't insert, use if let
73 if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
83 m.entry(k).or_insert_with(|| {
109 // ok, insert in loop
110 if !m.contains_key(&k) {
116 // macro_expansion test, use or_insert(..)
117 m.entry(m!(k)).or_insert_with(|| m!(v));
119 // ok, map used before insertion
120 if !m.contains_key(&k) {
126 if !m.contains_key(&k) {
127 unsafe { asm!("nop") }
131 // ok, different keys.
132 if !m.contains_key(&k) {
136 // ok, different maps
137 if !m.contains_key(&k) {
141 // ok, insert in macro
142 if !m.contains_key(&k) {
146 // or_insert_with. Partial move of a local declared in the closure is ok.
147 m.entry(k).or_insert_with(|| {
148 let x = (String::new(), String::new());