]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/derive_hash_xor_eq.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / derive_hash_xor_eq.txt
1 ### What it does
2 Checks for deriving `Hash` but implementing `PartialEq`
3 explicitly or vice versa.
4
5 ### Why is this bad?
6 The implementation of these traits must agree (for
7 example for use with `HashMap`) so it’s probably a bad idea to use a
8 default-generated `Hash` implementation with an explicitly defined
9 `PartialEq`. In particular, the following must hold for any type:
10
11 ```
12 k1 == k2 ⇒ hash(k1) == hash(k2)
13 ```
14
15 ### Example
16 ```
17 #[derive(Hash)]
18 struct Foo;
19
20 impl PartialEq for Foo {
21     ...
22 }
23 ```