//@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 insert_if_absent0(m: &mut HashMap, 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() {}