Two-arm match whose second arm does nothing
ID |
rust.maintainability.single_match |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Control Flow |
Language |
Rust |
Description
Reports a match with two arms where the second one is _ ⇒ (), _ ⇒ {}, None ⇒ () or None ⇒ {}, so only one arm carries behaviour. That is a conditional binding, which if let expresses directly.
Rationale
A match invites the reader to compare its arms, and here there is nothing to compare - the do-nothing arm exists only to satisfy exhaustiveness. It also costs four lines and a level of indentation for a single conditional, and an empty arm is easy to misread as an oversight rather than a deliberate no-op.
The following code illustrates the pattern detected by this rule:
pub fn wildcard_unit(o: Option<i32>) {
// FLAGGED: Two-arm match whose second arm does nothing
match o {
Some(v) => println!("{}", v),
_ => (),
}
}