]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/suspicious_operation_groupings.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / suspicious_operation_groupings.txt
1 ### What it does
2 Checks for unlikely usages of binary operators that are almost
3 certainly typos and/or copy/paste errors, given the other usages
4 of binary operators nearby.
5
6 ### Why is this bad?
7 They are probably bugs and if they aren't then they look like bugs
8 and you should add a comment explaining why you are doing such an
9 odd set of operations.
10
11 ### Known problems
12 There may be some false positives if you are trying to do something
13 unusual that happens to look like a typo.
14
15 ### Example
16 ```
17 struct Vec3 {
18     x: f64,
19     y: f64,
20     z: f64,
21 }
22
23 impl Eq for Vec3 {}
24
25 impl PartialEq for Vec3 {
26     fn eq(&self, other: &Self) -> bool {
27         // This should trigger the lint because `self.x` is compared to `other.y`
28         self.x == other.y && self.y == other.y && self.z == other.z
29     }
30 }
31 ```
32 Use instead:
33 ```
34 // same as above except:
35 impl PartialEq for Vec3 {
36     fn eq(&self, other: &Self) -> bool {
37         // Note we now compare other.x to self.x
38         self.x == other.x && self.y == other.y && self.z == other.z
39     }
40 }
41 ```