mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-14 17:48:10 +00:00
74 lines
1.7 KiB
Rust
74 lines
1.7 KiB
Rust
// 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<K: Eq + Hash + Copy, V: Copy>(m: &mut HashMap<K, V>, 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() {}
|