From e34bf94e7d78e74387485c3acfe219b1831311d3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 13:38:43 +0000 Subject: [PATCH] Create rule S905: Non-empty statements should change control flow or have at least one side-effect (#4698) * Add rust to rule S905 * Update RSPEC * Remove tag --------- Co-authored-by: yassin-kammoun-sonarsource Co-authored-by: yassin-kammoun-sonarsource --- rules/S905/rust/metadata.json | 7 ++++ rules/S905/rust/rule.adoc | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 rules/S905/rust/metadata.json create mode 100644 rules/S905/rust/rule.adoc diff --git a/rules/S905/rust/metadata.json b/rules/S905/rust/metadata.json new file mode 100644 index 0000000000..1896e05dba --- /dev/null +++ b/rules/S905/rust/metadata.json @@ -0,0 +1,7 @@ +{ + "tags": [ + "cwe", + "unused", + "clippy" + ] +} diff --git a/rules/S905/rust/rule.adoc b/rules/S905/rust/rule.adoc new file mode 100644 index 0000000000..5c32877c92 --- /dev/null +++ b/rules/S905/rust/rule.adoc @@ -0,0 +1,65 @@ +include::../summary.adoc[] + +== Why is this an issue? + +include::../description.adoc[] + +=== Exceptions + +The rule does not raise an issue on statements containing only a semicolon (``++;++``). + +== How to fix it + +include::../how-to-fix.adoc[] + +=== Code examples + +==== Noncompliant code example + +[source,rust,diff-id=1,diff-type=noncompliant] +---- +fn get_result() -> i32 { + let mut result = 42; + if should_be_zero() { + result == 0; // Noncompliant: no side effect, was an assignment intended? + } + result +} +---- + + +==== Compliant solution + +[source,rust,diff-id=1,diff-type=compliant] +---- +fn get_result() -> i32 { + let mut result = 42; + if should_be_zero() { + result = 0; // Compliant + } + result +} +---- + + +include::../see.adoc[] + +=== Documentation + +* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#no_effect + +ifdef::env-github,rspecator-view[] + +''' +== Implementation Specification +(visible only on this page) + +include::../message.adoc[] + +''' +== Comments And Links +(visible only on this page) + +include::../comments-and-links.adoc[] + +endif::env-github,rspecator-view[]