Two case clauses of a switch run the same statements

tx0/c:identical-case-bodiesstrictwarningmaintainability/duplicationdepth fastsmell

What it finds

case A: x = 1; break; ... case C: x = 1; break;: the same code under two labels is either a copy that should have been changed, or two labels that can share one clause.

The clauses must hold at least two statements besides the closing break.

From the rule's source, identical_case_bodies.rs.

Example from the rule's tests
int code(int kind, int *out){  switch (kind) {  case 1:    *out = 10;    return 1;  case 2:    *out = 20;    return 2;  case 3:    *out = 10;tx0 reports: this clause runs the same statements as an earlier one    return 1;  default:    return 0;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:identical-case-bodies" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/c:identical-case-bodies] reason="..."

tx0 explain tx0/c:identical-case-bodies shows the same in the terminal. Found a false positive? Report it.