fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] 2#![warn(clippy::map_entry)] 3 4use std::collections::{BTreeMap, HashMap}; 5use std::hash::Hash; 6 7macro_rules! m { 8 ($e:expr) => {{ $e }}; 9} 10 11fn foo() {} 12 13fn insert_if_absent0<K: Eq + Hash + Copy, V: Copy>(m: &mut HashMap<K, V>, k: K, v: V, v2: V) { 14 match m.entry(k) { 15 std::collections::hash_map::Entry::Vacant(e) => { 16 e.insert(v); 17 } 18 std::collections::hash_map::Entry::Occupied(mut e) => { 19 e.insert(v2); 20 } 21 } 22 23 match m.entry(k) { 24 std::collections::hash_map::Entry::Occupied(mut e) => { 25 e.insert(v); 26 } 27 std::collections::hash_map::Entry::Vacant(e) => { 28 e.insert(v2); 29 } 30 } 31 32 if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { 33 e.insert(v); 34 } else { 35 foo(); 36 } 37 38 if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { 39 e.insert(v); 40 } else { 41 foo(); 42 } 43 44 match m.entry(k) { 45 std::collections::hash_map::Entry::Vacant(e) => { 46 e.insert(v); 47 } 48 std::collections::hash_map::Entry::Occupied(mut e) => { 49 e.insert(v2); 50 } 51 } 52 53 match m.entry(k) { 54 std::collections::hash_map::Entry::Occupied(mut e) => { 55 if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } 56 } 57 std::collections::hash_map::Entry::Vacant(e) => { 58 e.insert(v); 59 None 60 } 61 }; 62 63 if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { 64 foo(); 65 Some(e.insert(v)) 66 } else { 67 None 68 }; 69} 70 71fn main() {}