]> git.lizzy.rs Git - rust.git/blob - src/docs/derive_partial_eq_without_eq.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / derive_partial_eq_without_eq.txt
1 ### What it does
2 Checks for types that derive `PartialEq` and could implement `Eq`.
3
4 ### Why is this bad?
5 If a type `T` derives `PartialEq` and all of its members implement `Eq`,
6 then `T` can always implement `Eq`. Implementing `Eq` allows `T` to be used
7 in APIs that require `Eq` types. It also allows structs containing `T` to derive
8 `Eq` themselves.
9
10 ### Example
11 ```
12 #[derive(PartialEq)]
13 struct Foo {
14     i_am_eq: i32,
15     i_am_eq_too: Vec<String>,
16 }
17 ```
18 Use instead:
19 ```
20 #[derive(PartialEq, Eq)]
21 struct Foo {
22     i_am_eq: i32,
23     i_am_eq_too: Vec<String>,
24 }
25 ```