Rust
Binding Shadows a Static E0530 Fix
A pattern name in Rust is not always a new binding. If the name already belongs to a static, a tuple struct, or a tuple variant, the compiler refuses to let a match arm or a `let` reuse it as a fresh variable, and reports E0530. The fix depends on what was meant: a new binding needs a new name, a comparison against the static needs an explicit test, and a variant or tuple struct needs its fields written in the pattern. This guide shows each failure, the nearby shapes that compile, and each repair running.
Written December 1, 2026 · Tested with Rust 1.99.0 · 17 min read
- The rule underneath: some names are already patterns
- How to read the diagnostic
- The first failure: a match arm named after a static
- A let binding named after a static is the same error
Written December 1, 2026
Tested with Rust 1.99.0
What this guide is
Error E0530 means a binding shadowed something it should not. The error codes index puts it in one line: "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", and adds that the error may also happen when an enum variant with fields is used in a pattern without its fields.
The index gives two erroneous examples. In the first, a tuple variant is used bare: matching on WithField(1) with the arm WithField => {}, commented "error: missing (_)". In the second, a match arm is named after a static: with static TEST: i32 = 0; in scope, the arm TEST => {} is commented "error: name of a static". Its fixed examples rename the arm to some_value, and show the same arm compiling when TEST is a const instead of a static, commented "const is ok!".
Those examples are the center of a wider family, and the boundaries matter. A let binding named after a static draws the same code with its own header. A bare tuple-struct name draws it too. But a plain struct name used as an arm, a unit struct, and a unit variant do not draw it at all, and a bare name that is not in scope as a static, variant, or tuple struct is simply an ordinary binding, even if an associated constant elsewhere shares the spelling. Nearby pattern mistakes draw different codes entirely - E0532, E0533, E0164, and E0423 - and each is shown in its own section below, under its own code.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.
The rule underneath: some names are already patterns
A single identifier in a pattern is ambiguous in principle: it could introduce a new variable that matches anything, or it could refer to an existing item - a constant, a static, a unit struct, a unit variant - and match only that item's value. Rust resolves the ambiguity by reserving the second reading for the items that can appear in patterns. A const, a unit struct, and a unit variant used as a pattern are read as themselves, not as new bindings.
Statics sit in an awkward middle: a static's value is not known at compile time in the way a constant's is, so a static cannot be used as a pattern - yet its name is still not free for a binding to take. The compiler therefore rejects the binding outright with E0530 instead of silently choosing either reading. Tuple structs and tuple variants have the parallel problem in reverse: their names denote constructors that take fields, so a bare name with no fields is neither a complete pattern for the constructor nor a free binding, and it is rejected with the same code and a help line pointing at the missing arguments.
That is why the intent decides the repair. If a new variable was meant, it needs a name nobody else owns. If a comparison was meant, it has to be written as a comparison. If the constructor was meant, its fields have to appear in the pattern.
How to read the diagnostic
The header names both the binding kind and the thing shadowed. For a match arm against a static it reads "match bindings cannot shadow statics"; for a let it reads "let bindings cannot shadow statics"; for a bare tuple variant, "match bindings cannot shadow tuple variants"; for a bare tuple struct, "match bindings cannot shadow tuple structs". The span underlines the offending name, with the note "cannot be named the same as a static", "cannot be named the same as a tuple variant", or "cannot be named the same as a tuple struct". For the static cases a second span points back to the definition: "the static TEST is defined here". For the tuple variant case it points to the import: "the tuple variant WithField is imported here".
The tuple cases carry a help line the static cases do not: "try specify the pattern arguments: WithField(..)" or "Bar(..)". There is no equivalent help for the static cases, because there is no pattern form of a static to suggest - the repair there is a rename or an explicit comparison, and the compiler leaves that choice to the code.
Two warnings often ride along and are not the error: the arm is also reported as an unused variable, and any following arm as unreachable, because the rejected name was still treated as a catch-all binding for those lints. Fix the E0530 and both warnings go with it.
The first failure: a match arm named after a static
The index's static example, with a body on each arm:
static TEST: i32 = 0;
fn main() {
let r = 123;
match r {
TEST => println!("matched"),
_ => println!("other"),
}
}
error[E0530]: match bindings cannot shadow statics
--> fail_match_static.rs:5:9
|
1 | static TEST: i32 = 0;
| --------------------- the static `TEST` is defined here
...
5 | TEST => println!("matched"),
| ^^^^ cannot be named the same as a static
warning: unreachable pattern
--> fail_match_static.rs:6:9
|
5 | TEST => println!("matched"),
| ---- matches any value
6 | _ => println!("other"),
| ^ no value can reach this
|
= note: `#[warn(unreachable_patterns)]` (part of `#[warn(unused)]`) on by default
warning: unused variable: `TEST`
--> fail_match_static.rs:5:9
|
5 | TEST => println!("matched"),
| ^^^^ help: if this is intentional, prefix it with an underscore: `_TEST`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 2 warnings emitted
For more information about this error, try `rustc --explain E0530`.
Nothing here compares r against the static. That is the trap the error protects against: written as a binding, TEST would match every value and bind it, so the arm looks like a test for 0 and behaves like a catch-all. The compiler refuses both readings. The repairs - renaming the arm, and comparing explicitly with a guard - are shown running at the end of this guide.
A let binding named after a static is the same error
The index phrases the rule for match arms and variables together, and a plain let draws E0530 with its own header:
static TEST: i32 = 0;
fn main() {
let TEST = 123;
println!("{}", TEST);
}
error[E0530]: let bindings cannot shadow statics
--> fail_let_static.rs:3:9
|
1 | static TEST: i32 = 0;
| --------------------- the static `TEST` is defined here
2 | fn main() {
3 | let TEST = 123;
| ^^^^ cannot be named the same as a static
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0530`.
The same holds when the static is declared inside the function, before the let, and when the name appears inside a pattern in an if let - if let Some(TEST) = r draws E0530 with the header "let bindings cannot shadow statics" as well. So the restriction is not specific to match: any binding position that would take the static's name is rejected. Rename the variable; a let has no guard or field form to rescue it.
The exception the index states: a const is fine in a match arm
Change static to const and the identical match compiles and runs:
const TEST: i32 = 0;
fn main() {
let r = 123;
match r {
TEST => println!("zero"),
other_values => println!("other {}", other_values),
}
}
other 123
The output is other 123: the TEST arm did not fire for 123, because here TEST is read as the constant pattern - it matches only the value 0 - and the catch-all binding is the differently named other_values. This is the asymmetry at the heart of the error: constants can be patterns, statics cannot, so a constant's name in an arm is a pattern and a static's name in an arm is a rejected binding. Note the counterpart in a let: let TEST = 123; with a const TEST in scope does not draw E0530 - it draws E0005, because the let reads TEST as a constant pattern and a constant pattern is refutable, which a let does not allow. That is a different code for a different defect, not this guide's error.
A variant with fields, used without them
The index's other example is a tuple variant used as a bare pattern:
enum Enum { WithField(i32) }
use Enum::*;
fn main() {
match WithField(1) {
WithField => println!("matched"),
}
}
error[E0530]: match bindings cannot shadow tuple variants
--> fail_variant_bare.rs:5:9
|
2 | use Enum::*;
| ------- the tuple variant `WithField` is imported here
...
5 | WithField => println!("matched"),
| ^^^^^^^^^
| |
| cannot be named the same as a tuple variant
| help: try specify the pattern arguments: `WithField(..)`
warning: unused variable: `WithField`
--> fail_variant_bare.rs:5:9
|
5 | WithField => println!("matched"),
| ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_WithField`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0530`.
The header says "shadow tuple variants", even though the practical reading is the index's: the variant was used without its fields. Both readings point at the same line and the same repair - write the fields, as WithField(n) or WithField(..), or qualify the pattern as Enum::WithField(n); the repairs below show WithField(n) running and state the outputs of the wildcard and qualified forms. Writing the name with parentheses but the wrong kind of pattern is a different error: E::V(_) against a struct variant draws E0164, in its own section below.
A tuple struct used bare is the same code
A tuple struct is a constructor in the same way, and its bare name in a pattern draws E0530:
struct Bar(i32);
fn main() {
match Bar(1) {
Bar => println!("matched"),
}
}
error[E0530]: match bindings cannot shadow tuple structs
--> fail_tuple_struct.rs:4:9
|
1 | struct Bar(i32);
| ---------------- the tuple struct `Bar` is defined here
...
4 | Bar => println!("matched"),
| ^^^
| |
| cannot be named the same as a tuple struct
| help: try specify the pattern arguments: `Bar(..)`
warning: unused variable: `Bar`
--> fail_tuple_struct.rs:4:9
|
4 | Bar => println!("matched"),
| ^^^ help: if this is intentional, prefix it with an underscore: `_Bar`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0530`.
The repair mirrors the variant case: Bar(n) binds the field and prints it, as shown in the repairs, and Bar(..) matches without binding it.
The shapes that are not this error: plain structs, unit items, associated constants
Three nearby shapes compile, and they mark the exact edge of the rule.
A plain struct name - a struct with named fields - used as a match arm is an ordinary binding, not E0530. Matching a Foo { x: 1 } value with the arm Foo => println!("matched") compiles (with unused-variable and naming warnings only) and prints matched: the arm binds the whole value to a new variable that happens to be spelled Foo. Only the tuple form of a struct is protected, because only the tuple form is a constructor that a bare pattern could be mistaken for.
A unit struct and a unit variant used as patterns compile for the opposite reason: they are read as themselves. Unit => ... against a unit struct value prints matched, and A => ... against a unit variant prints a - in both cases the name is a pattern matching that one value, not a binding at all, so there is nothing to shadow. The trap is in a let: with a unit variant imported, let A = 5; is read as a pattern too, and fails with mismatched-type and trait errors (E0308 and E0277 in the probed program), not E0530 - the compiler's help there is "introduce a new binding instead".
An associated constant's bare name is not in scope as a pattern at all. With impl S { const C: i32 = 0; } in the program, the arm C => ... compiles as an ordinary catch-all binding and prints matched for 123 - the associated constant is only reachable by its path. Written as a path, S::C => ... is a constant pattern: it compiles and, for the value 0, prints zero. So the index's mention of associated constants does not mean a bare arm named after one draws E0530 in this form; in the probed forms it either binds freely or, by path, matches as a constant.
Neighboring codes: E0532, E0533, E0164, E0423
Four pattern mistakes sit next to E0530 and are routinely confused with it. Each keeps its own code.
Expected a pattern item, found a tuple variant - E0532. Using a tuple variant where a unit item was expected, if let E::V = e, draws E0532: "expected unit struct, unit variant or constant, found tuple variant E::V", with the help "use the tuple variant pattern syntax instead: E::V(_)". That guide is E0532.
Expected a pattern item, found a struct variant - E0533. Using a struct variant bare, E::V => ... where V has named fields, draws E0533: "expected unit struct, unit variant or constant, found struct variant E::V", with help adding the field names. Note the asymmetry with E0530: a bare tuple variant is E0530, a bare struct variant is E0533. That guide is E0533.
A tuple pattern against a struct variant - E0164. Writing E::V(_) for a struct variant draws E0164: "expected tuple struct or tuple variant, found struct variant E::V", with help rewriting the pattern with field names. The fields are present here - present in the wrong shape - which is what separates E0164 from both E0530 and E0533.
A struct name used as a value - E0423. Outside patterns entirely, using a plain struct's name as a value, let y = S; for struct S { x: i32 }, draws E0423, with help offering the struct literal syntax. That is a value-position mistake, not a binding or pattern mistake. That guide is E0423.
The repairs
Rename the binding. This is the index's own fix for the static case - the arm keeps its catch-all meaning under a name nobody owns:
static TEST: i32 = 0;
fn main() {
let r = 123;
match r {
some_value => println!("got {}", some_value),
}
}
got 123
The output is got 123. Choose this repair whenever a new variable was what the arm - or the let - actually meant.
Compare against the static explicitly. A static cannot be a pattern, but it can be compared against in a guard:
static TEST: i32 = 0;
fn main() {
let r = 0;
match r {
x if x == TEST => println!("is TEST"),
x => println!("other {}", x),
}
}
is TEST
The output is is TEST, because r is 0 and the guard compares it against the static's value. Choose this repair when the arm was meant to fire only for the static's value - the reading the bare name seemed to promise and cannot deliver.
Give the variant its fields. Binding the field:
enum Enum { WithField(i32) }
use Enum::*;
fn main() {
match WithField(1) {
WithField(n) => println!("got {}", n),
}
}
got 1
The output is got 1. The wildcard form the compiler's help suggests, WithField(..), also compiles and runs, printing matched in the probed program. The fully qualified form compiles and runs as well - Enum::WithField(n) against Enum::WithField(1) prints got 1 - and needs no import.
Give the tuple struct its fields, the same way:
struct Bar(i32);
fn main() {
match Bar(7) {
Bar(n) => println!("got {}", n),
}
}
got 7
The output is got 7. And where the item really should be usable as a pattern, change the item, not the arm: the index's second fix makes TEST a const, after which the arm TEST => ... is a constant pattern matching only 0, as shown in the const section above.
Fixes in reach order
First, decide what the name was meant to do. Every E0530 repair follows from that one decision, and applying the wrong one silently changes the match: a rename keeps a catch-all, a guard makes a test, and a field pattern makes a constructor match.
Second, if a new variable was meant, rename it - in a match arm, in a let, or inside an if let pattern. This is the only repair a let against a static has.
Third, if a comparison against the static was meant, write it as a guard, x if x == TEST, or restructure the match into an if. Do not expect the bare name to test anything: a static is never a pattern.
Fourth, if a variant or tuple struct was meant, write its fields: WithField(n), WithField(..), Bar(n), or the qualified Enum::WithField(n). Follow the compiler's help line literally - it names the exact form.
Last, check the code before assuming E0530. A bare struct variant is E0533, a tuple variant in a unit position is E0532, a tuple pattern on a struct variant is E0164, and a struct name used as a value is E0423 - each has its own repair, and none is fixed by renaming a binding.
Decision summary
E0530 fired in every probed shadowing shape: a match arm named after a static, a let named after a static (at module level and inside the function), a name inside an if let pattern against a static, a bare tuple-variant pattern, and a bare tuple-struct pattern - with headers naming the binding kind and the thing shadowed, and a "try specify the pattern arguments" help on the tuple cases only. It did not fire for a const in a match arm, which compiled as a constant pattern; for a plain struct name as an arm, a unit struct, or a unit variant, which compiled as bindings or as patterns; or for an associated constant, whose bare name compiled as an ordinary binding and whose path form compiled as a constant pattern. Neighboring shapes drew their own codes: E0532, E0533, E0164, E0423, E0005 for a let against a const, and E0308 with E0277 for a let against an imported unit variant. Compiling and running were: the renamed arm, the guard comparison against the static, the const arm, and the variant and tuple-struct patterns with fields, in binding, wildcard, and qualified forms.
Checklist
- The defect is the name, not the value: a binding may not take the name of a static, a tuple struct, or a tuple variant in scope.
- Match arms and
letbindings both draw E0530 against a static, with headers naming the binding kind. - A
constis the exception in a match arm: its name is a constant pattern matching only its value. A static is never a pattern. - To test against a static's value, compare in a guard:
x if x == TEST. - A variant or tuple struct used bare is E0530; write its fields -
WithField(n),WithField(..),Bar(n)- or qualify it. - A plain struct name, a unit struct, and a unit variant do not draw E0530 in a pattern; an associated constant's bare name is an ordinary binding, and its path form is a constant pattern.
- A bare struct variant is E0533, not E0530; a tuple pattern on a struct variant is E0164; a tuple variant in a unit position is E0532; a struct name as a value is E0423.
Related guides on this site
- E0005 Refutable Pattern in Local Binding Fix
- impl Trait in Let Binding E0562 Fix
- Fix Rust E0596 "cannot borrow as mutable" — a Vec Without mut, a Function Taking &Vec, a &self Method Pushing to a Field, and a Shared Reference in a Binding
- Rust Lazy Statics, Measured: OnceLock vs LazyLock vs lazy_static — and the 2x Claim That Does Not Reproduce
Sources
- Rust error codes index, E0530 - a binding shadowed something it should not: a match arm or variable with a name already used by a struct name, enum variant, static, or associated constant; the error may also happen when an enum variant with fields is used in a pattern without its fields; the erroneous examples are the bare
WithFieldarm and the match armTESTagainst astatic, and the fixed examples rename the arm and change thestaticto aconst. - The Rust Reference, Patterns - the pattern grammar and the identifier, wildcard, and path pattern forms that decide whether a single name in a pattern is a new binding or a reference to an existing constant, static, struct, or variant.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.