]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_key.rs
new lint: mutable_key_type
[rust.git] / tests / ui / mut_key.rs
1 use std::collections::{HashMap, HashSet};
2 use std::hash::{Hash, Hasher};
3 use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
4
5 struct Key(AtomicUsize);
6
7 impl Clone for Key {
8     fn clone(&self) -> Self {
9         Key(AtomicUsize::new(self.0.load(Relaxed)))
10     }
11 }
12
13 impl PartialEq for Key {
14     fn eq(&self, other: &Self) -> bool {
15         self.0.load(Relaxed) == other.0.load(Relaxed)
16     }
17 }
18
19 impl Eq for Key {}
20
21 impl Hash for Key {
22     fn hash<H: Hasher>(&self, h: &mut H) {
23         self.0.load(Relaxed).hash(h);
24     }
25 }
26
27 fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
28     let _other: HashMap<Key, bool> = HashMap::new();
29     m.keys().cloned().collect()
30 }
31
32 fn this_is_ok(m: &mut HashMap<usize, Key>) {}
33
34 fn main() {
35     let _ = should_not_take_this_arg(&mut HashMap::new(), 1);
36     this_is_ok(&mut HashMap::new());
37 }