2
0
Fork 0
mirror of https://github.com/rust-lang/rust-clippy synced 2024-12-23 19:43:20 +00:00
rust-clippy/tests/ui/entry_with_else.fixed

71 lines
1.7 KiB
Rust

#![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() {}