]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_key.rs
Merge commit '7ea7cd165ad6705603852771bf82cc2fd6560db5' into clippyup2
[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 #[allow(unused)]
35 trait Trait {
36     type AssociatedType;
37
38     fn trait_fn(&self, set: std::collections::HashSet<Self::AssociatedType>);
39 }
40
41 fn generics_are_ok_too<K>(_m: &mut HashSet<K>) {
42     // nothing to see here, move along
43 }
44
45 fn tuples<U>(_m: &mut HashMap<((), U), ()>) {}
46
47 fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {}
48
49 fn main() {
50     let _ = should_not_take_this_arg(&mut HashMap::new(), 1);
51     this_is_ok(&mut HashMap::new());
52     tuples::<Key>(&mut HashMap::new());
53     tuples::<()>(&mut HashMap::new());
54     tuples_bad::<()>(&mut HashMap::new());
55 }