rspec/rules/S7423/rust/rule.adoc
github-actions[bot] 66bae183f4
Create rule S7423: Unit values should not be compared (#4764)
* 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>
2025-03-19 13:07:11 +00:00

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