// run-rustfix #![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 hash_map(m: &mut HashMap, k: K, v: V, v2: V) { m.entry(k).or_insert(v); m.entry(k).or_insert_with(|| { if true { v } else { v2 } }); m.entry(k).or_insert_with(|| { if true { v } else { v2 } }); if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { if true { e.insert(v); } else { e.insert(v2); return; } } m.entry(k).or_insert_with(|| { foo(); v }); m.entry(k).or_insert_with(|| { match 0 { 1 if true => { v }, _ => { v2 }, } }); if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { match 0 { 0 => {}, 1 => { e.insert(v); }, _ => { e.insert(v2); }, }; } m.entry(k).or_insert_with(|| { foo(); match 0 { 0 if false => { v }, 1 => { foo(); v }, 2 | 3 => { for _ in 0..2 { foo(); } if true { v } else { v2 } }, _ => { v2 }, } }); m.entry(m!(k)).or_insert_with(|| m!(v)); } fn btree_map(m: &mut BTreeMap, k: K, v: V, v2: V) { if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { e.insert(v); foo(); } } fn main() {}