41 lines
707 B
Plaintext
41 lines
707 B
Plaintext
![]() |
== Why is this an issue?
|
||
|
|
||
|
The unit type `()` is always equal to itself and using it in comparisons is either redundant or a mistake, often caused by accidental semicolon placement.
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
fn foo() {}
|
||
|
fn bar() {}
|
||
|
fn baz() {}
|
||
|
|
||
|
if {
|
||
|
foo();
|
||
|
} == {
|
||
|
bar();
|
||
|
} {
|
||
|
baz();
|
||
|
} // Noncompliant: Comparing unit values.
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
fn foo() {}
|
||
|
fn bar() {}
|
||
|
fn baz() {}
|
||
|
|
||
|
foo();
|
||
|
bar();
|
||
|
baz(); // Compliant: No unit comparison.
|
||
|
----
|
||
|
|
||
|
== Resources
|
||
|
=== Documentation
|
||
|
|
||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
|