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.
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
- E0004non-exhaustive patterns
- E0527pattern requires 2 elements but array has 4
- E0528pattern requires at least 3 elements but array has 2
- E0532expected unit struct, unit variant or constant, found tuple variant `State::Failed`
- E0533expected unit struct, unit variant or constant, found associated function `Tortoise::turtle`
Up next
Often hit nextE0004: non-exhaustive patternsA related error from the same family.Read it next →Did this answer your question?