// compile-flags: --crate-name mut_key #![warn(clippy::mutable_key_type)] use std::cmp::{Eq, PartialEq}; use std::collections::{HashMap, HashSet}; use std::hash::{Hash, Hasher}; use std::ops::Deref; use std::sync::atomic::{AtomicUsize, Ordering}; struct Counted { count: AtomicUsize, val: T, } impl Clone for Counted { fn clone(&self) -> Self { Self { count: AtomicUsize::new(0), val: self.val.clone(), } } } impl PartialEq for Counted { fn eq(&self, other: &Self) -> bool { self.val == other.val } } impl Eq for Counted {} impl Hash for Counted { fn hash(&self, state: &mut H) { self.val.hash(state); } } impl Deref for Counted { type Target = T; fn deref(&self) -> &T { self.count.fetch_add(1, Ordering::AcqRel); &self.val } } // This is not linted because `"mut_key::Counted"` is in // `arc_like_types` in `clippy.toml` fn should_not_take_this_arg(_v: HashSet>) {} fn main() { should_not_take_this_arg(HashSet::new()); }