![github-actions[bot]](/assets/img/avatar_default.png)
* Create rule S7423 * Update RSPEC --------- Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
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
|