]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/src/docs/unit_cmp.txt
New upstream version 1.65.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / unit_cmp.txt
1 ### What it does
2 Checks for comparisons to unit. This includes all binary
3 comparisons (like `==` and `<`) and asserts.
4
5 ### Why is this bad?
6 Unit is always equal to itself, and thus is just a
7 clumsily written constant. Mostly this happens when someone accidentally
8 adds semicolons at the end of the operands.
9
10 ### Example
11 ```
12 if {
13 foo();
14 } == {
15 bar();
16 } {
17 baz();
18 }
19 ```
20 is equal to
21 ```
22 {
23 foo();
24 bar();
25 baz();
26 }
27 ```
28
29 For asserts:
30 ```
31 assert_eq!({ foo(); }, { bar(); });
32 ```
33 will always succeed