Two match arms share an identical body
ID |
rust.maintainability.match_same_arms |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Redundancy |
Language |
Rust |
Description
Two arms of this match evaluate to the same expression. Combine their patterns with | so the shared result is written once.
Rationale
Two arms of this match evaluate to the same expression. Combine their patterns with | so the shared result is written once.
The following code illustrates the pattern detected by this rule:
pub fn classify(n: i32) -> i32 {
// FLAGGED: Two match arms share an identical body
match n {
1 => 10,
2 => 10,
_ => 0,
}
}