Compare commits

...

4 Commits

Author SHA1 Message Date
Gyula Sallai
828072f64b
Update metadata.json 2025-03-27 16:20:33 +01:00
Gyula Sallai
4881d94421
Update rule.adoc 2025-03-26 13:52:31 +01:00
Gyula Sallai
0b08f51c46
Update metadata.json 2025-03-26 13:51:59 +01:00
sallaigy
3bfac26d7b Create rule S7457 2025-03-26 12:42:09 +00:00
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,24 @@
{
"title": "Calls to `step_by` that always panic should not be made",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Blocker",
"ruleSpecification": "RSPEC-7457",
"sqKey": "S7457",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "HIGH"
},
"attribute": "LOGICAL"
}
}

View File

@ -0,0 +1,28 @@
== Why is this an issue?
Calling `.step_by(0)` on an iterator will cause the program to panic. This is likely an oversight and should be corrected to ensure program stability. If the intent is to cause a panic, it is clearer to use `panic!()` directly.
=== Code examples
==== Noncompliant code example
[source,rust,diff-id=1,diff-type=noncompliant]
----
for x in (0..100).step_by(0) { // Noncompliant: This will cause a panic.
// ...
}
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
for x in (0..100).step_by(1) { // Compliant: Step by a valid positive integer.
// ...
}
----
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero