Both branches of an if/else run the same code
ID |
rust.correctness.duplicate_branches |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Duplicate Logic |
Language |
Rust |
Description
Both branches of this if evaluate to exactly the same code, so the condition has no effect on what runs. Either one branch was meant to differ, or the if can be dropped and the shared code written once.
Rationale
Both branches of this if evaluate to exactly the same code, so the condition has no effect on what runs. Either one branch was meant to differ, or the if can be dropped and the shared code written once.
The following code illustrates the pattern detected by this rule:
fn log_state(active: bool) {
// FLAGGED: Both branches of an if/else run the same code
if active {
println!("state changed");
} else {
println!("state changed");
}
}