tripon[github]

diagnostic codes / Types

E0212 duplicate-match-arm

The same variant is matched twice.

E0212duplicate-match-armremove or reorder the repeated arm; match arms are checked top to bottom
severityerror
bandTypes
in the v0 bootstrapemitted
explainralt explain E0212

Arm matching is top to bottom, so the second arm for a variant is unreachable. The check reports the repeated variant, not the arm body. It applies to enum variants and to the `some`/`none` and `ok`/`err` constructors.

What it looks like

e0212.tp
use tier core;

enum E { A, B }

fn main() -> i32 {
    let e = E::A;
    match e {
        E::A => { print_str("a"); }
        E::A => { print_str("b"); }
        E::B => { }
    }
    return 0;
}
ralt check e0212.tp
e0212.tp:9:9: error: duplicate match arm: variant 'A' already covered
  [E0212 duplicate-match-arm] remove or reorder the repeated arm; match arms are checked top to bottom

What to do

  • Delete the later arm, or change its pattern to the variant it was meant to be.
  • If the intent was an ordered decision, the first arm already won; there is no pattern ranking in v0.

Why the code exists

A duplicate arm is always a copy-paste bug, never a feature. Reporting it at the duplicate keeps the reader from having to reason about which body runs.

What ralt explain says

ralt explain E0212
E0212
severity: error
name: duplicate-match-arm
hint: remove or reorder the repeated arm; match arms are checked top to bottom

Related