// 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); if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { if true { e.insert(v); } else { e.insert(v2); } } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { if true { e.insert(v); } else { e.insert(v2); return; } } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { foo(); e.insert(v); } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { match 0 { 1 if true => { e.insert(v); }, _ => { e.insert(v2); }, }; } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { match 0 { 0 => {}, 1 => { e.insert(v); }, _ => { e.insert(v2); }, }; } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { foo(); match 0 { 0 if false => { e.insert(v); }, 1 => { foo(); e.insert(v); }, 2 | 3 => { for _ in 0..2 { foo(); } if true { e.insert(v); } else { e.insert(v2); }; }, _ => { e.insert(v2); }, } } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(m!(k)) { e.insert(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() {}