]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_key.rs
Auto merge of #4809 - iankronquist:patch-1, r=flip1995
[rust.git] / tests / ui / mut_key.rs
1 #![allow(clippy::implicit_hasher)]
2
3 use std::collections::{HashMap, HashSet};
4 use std::hash::{Hash, Hasher};
5 use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
6
7 struct Key(AtomicUsize);
8
9 impl Clone for Key {
10     fn clone(&self) -> Self {
11         Key(AtomicUsize::new(self.0.load(Relaxed)))
12     }
13 }
14
15 impl PartialEq for Key {
16     fn eq(&self, other: &Self) -> bool {
17         self.0.load(Relaxed) == other.0.load(Relaxed)
18     }
19 }
20
21 impl Eq for Key {}
22
23 impl Hash for Key {
24     fn hash<H: Hasher>(&self, h: &mut H) {
25         self.0.load(Relaxed).hash(h);
26     }
27 }
28
29 fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
30     let _other: HashMap<Key, bool> = HashMap::new();
31     m.keys().cloned().collect()
32 }
33
34 fn this_is_ok(_m: &mut HashMap<usize, Key>) {}
35
36 #[allow(unused)]
37 trait Trait {
38     type AssociatedType;
39
40     fn trait_fn(&self, set: std::collections::HashSet<Self::AssociatedType>);
41 }
42
43 fn generics_are_ok_too<K>(_m: &mut HashSet<K>) {
44     // nothing to see here, move along
45 }
46
47 fn tuples<U>(_m: &mut HashMap<((), U), ()>) {}
48
49 fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {}
50
51 fn main() {
52     let _ = should_not_take_this_arg(&mut HashMap::new(), 1);
53     this_is_ok(&mut HashMap::new());
54     tuples::<Key>(&mut HashMap::new());
55     tuples::<()>(&mut HashMap::new());
56     tuples_bad::<()>(&mut HashMap::new());
57 }