diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:21 +0000 |
commit | 4e8199b572f2035b7749cba276ece3a26630d23e (patch) | |
tree | f09feeed6a0fe39d027b1908aa63ea6b35e4b631 /src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs | |
parent | Adding upstream version 1.66.0+dfsg1. (diff) | |
download | rustc-4e8199b572f2035b7749cba276ece3a26630d23e.tar.xz rustc-4e8199b572f2035b7749cba276ece3a26630d23e.zip |
Adding upstream version 1.67.1+dfsg1.upstream/1.67.1+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs b/src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs new file mode 100644 index 000000000..667c51cb4 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs @@ -0,0 +1,53 @@ +// 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<T> { + count: AtomicUsize, + val: T, +} + +impl<T: Clone> Clone for Counted<T> { + fn clone(&self) -> Self { + Self { + count: AtomicUsize::new(0), + val: self.val.clone(), + } + } +} + +impl<T: PartialEq> PartialEq for Counted<T> { + fn eq(&self, other: &Self) -> bool { + self.val == other.val + } +} +impl<T: PartialEq + Eq> Eq for Counted<T> {} + +impl<T: Hash> Hash for Counted<T> { + fn hash<H: Hasher>(&self, state: &mut H) { + self.val.hash(state); + } +} + +impl<T> Deref for Counted<T> { + 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<Counted<String>>) {} + +fn main() { + should_not_take_this_arg(HashSet::new()); +} |