Two branches of an if/else-if chain test the same condition
ID |
rust.correctness.duplicate_conditions |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Duplicate Logic |
Language |
Rust |
Description
This else if repeats a condition already tested earlier in the same chain, so its branch can never run. Correct the duplicated condition, or delete the unreachable branch.
Rationale
This else if repeats a condition already tested earlier in the same chain, so its branch can never run. Correct the duplicated condition, or delete the unreachable branch.
The following code illustrates the pattern detected by this rule:
fn classify(value: i32, limit: i32) -> &'static str {
// FLAGGED: Two branches of an if/else-if chain test the same condition
if value > limit {
"over"
} else if value > limit {
"way over"
} else {
"under"
}
}