Email me

Rust errors / Patterns and matching

Rust compiler error · checked with rustc 1.99.0

Rust error E0530: match bindings cannot shadow tuple variants

What it meansA binding shadowed something it shouldn't.

What rustc prints

error[E0530]: match bindings cannot shadow tuple variants
 --> main.rs:9:5
  |
7 | use Enum::*;
  |     ------- the tuple variant `WithField` is imported here
8 | match WithField(1) {
9 |     WithField => {} // error: missing (_)
  |     ^^^^^^^^^
  |     |
  |     cannot be named the same as a tuple variant
  |     help: try specify the pattern arguments: `WithField(..)`

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

E0530Patterns and matching
Activein rustc 1.99.0
5related errors linked below

The compiler team's explanation

A binding shadowed something it shouldn't.

A match arm or a variable has a name that is already used by something else, e.g.

  • struct name
  • enum variant
  • static
  • associated constant

This error may also happen when an enum variant *with fields* is used in a pattern, but without its fields.

enum Enum {
    WithField(i32)
}

use Enum::*;
match WithField(1) {
    WithField => {} // error: missing (_)
}

Match bindings cannot shadow statics:

static TEST: i32 = 0;

let r = 123;
match r {
    TEST => {} // error: name of a static
}

Fixed examples:

static TEST: i32 = 0;

let r = 123;
match r {
    some_value => {} // ok!
}

or

const TEST: i32 = 0; // const, not static

let r = 123;
match r {
    TEST => {} // const is ok!
    other_values => {}
}

From rustc --explain E0530 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0004: non-exhaustive patternsA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ