Rust
E0409 Bound Inconsistently Across Patterns Fix
Every alternative of an or-pattern feeds one arm body, so a variable that one alternative binds as mutable, or by reference, has to be bound the same way in all of them. E0409 is the compiler naming the variable whose binding mode changes between alternatives. This guide works the shapes that produce it and matches each one to its repair: make the mode the same in every alternative, or split the pattern so each binding keeps its own arm.
Written November 29, 2026 · Tested with Rust 1.99.1 · 23 min read
- The rule underneath: the same variable, the same mode, in every alternative
- How to read the diagnostic
- The first failure: mut in one tuple position, plain in the other
- The second failure: mut inside one Some, plain inside the other
Written November 29, 2026
Tested with Rust 1.99.1
What this guide is
Error E0409 is an or-pattern whose alternatives bind the same variable in different ways. The error codes index defines it with the same opening sentence as its neighbor E0408 - an "or" pattern was used where the variable bindings are not consistently bound across patterns - and then gives an example of the specific disagreement this code covers: (0, ref y) | (y, 0), where y is bound by reference in one alternative and by value in the other. The index gives the two repairs this guide uses throughout: use the same mode in both cases - generally adding ref or ref mut where it is not already used - or split the pattern into separate arms.
The forms in this guide each reproduce E0409 with a small, complete program, and each changes the binding mode in a different place. mut in one tuple position and plain in the other. mut inside one Some and plain inside a second Some standing next to it. mut on one struct field and plain on the other. ref against plain, which changes the variable's type at the same time. ref mut against ref, which changes the reference's mutability. And the same mut mismatch one level down, in an or-pattern nested inside a tuple pattern.
Two neighboring results are not E0409 alone, and both are worked in the traps. A variable bound by reference in one alternative and by value in the other also changes type - &i32 against i32 - so the ref failures draw E0308 alongside E0409. And the two errors on either side of this one stay separate: a variable missing from an alternative is E0408, and a variable whose type differs while its mode stays the same is E0308 by itself.
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: the same variable, the same mode, in every alternative
An or-pattern - A | B | C - matches when any one of its alternatives matches, and the code after the => runs without knowing which one it was. The body receives one variable, so that variable has to arrive the same way on every path: the body either may reassign it or may not, and it either holds the value itself or holds a reference to it, and the alternatives do not get to disagree about which. The Rust Reference's patterns chapter states the constraint as one of three ways an or-pattern can be ill-formed: the type or binding mode of any two bindings with the same name do not unify. A missing binding is the first clause's territory and is E0408; a type that does not unify is E0308; a binding mode that does not unify is this error, E0409.
Binding mode here means the modifiers written at the binding site: plain (by value, immutable), mut (by value, mutable), ref (by shared reference), and ref mut (by mutable reference). Two of the four change more than the mode. Adding ref changes the type of the variable from the value's type to a reference to it, which is why the fourth and fifth failures also draw E0308: the compiler reports the mode disagreement as E0409 and the resulting type disagreement as E0308, and both have to be repaired - making the modes agree repairs both at once, because the types then agree as well.
The fix follows from the rule. Make the mode the same in every alternative: add mut to the plain alternative when the body reassigns the variable, or drop mut from the mutable one when it does not; add ref to the by-value alternative, as the error index prescribes, when a reference is what the body wants. Or split the pattern, giving each alternative its own arm and its own body, so the two bindings never have to unify - the right repair when the two cases genuinely want different modes, because they do different things with the variable. What never works is keeping one arm and adjusting the body: the body cannot ask which alternative matched, so it cannot adapt to a mode that changes per path.
How to read the diagnostic
The header states the defect in full: "variable y is bound inconsistently across alternatives separated by |". Below it, two spans locate the disagreement. A short span, underlined with a single dash, marks the first binding - labeled "first binding". A caret span marks the binding in the later alternative - labeled "bound in different ways". Reading the two together gives the repair directly: the caret-marked binding takes the first binding's mode, the first binding takes the caret-marked one's mode, or the arm splits.
One warning usually travels with the mut forms of this error, and it often names the cheaper repair. When the body never reassigns the variable, the compiler also warns "variable does not need to be mutable" and offers to remove the mut. That warning is a hint about intent: if nothing in the body mutates the variable, the mut was probably stray, and dropping it from the one alternative is the whole fix. If the body does reassign the variable, the warning is absent - the program needs the mutability - and the repair runs the other way, adding mut to the plain alternative.
That reading also separates this error from its neighbors before any repair starts. When one alternative does not bind the variable at all, the header is E0408, "not bound in all patterns", not this one. When every alternative binds the variable the same way but the values have different types, the header is E0308 alone, with the note that a binding must have the same type in all alternatives. E0409 appears only when the modes themselves differ - and when a ref is one of the modes, expect E0308 to stand next to it, for the type reason above.
The first failure: mut in one tuple position, plain in the other
This is the plainest form of the error. Whichever position holds the 0, the other position supplies y - but the first alternative binds it as mut y and the second as plain y, so the body would hold a variable that is mutable on one path and immutable on the other:
fn main() {
let pair: (i32, i32) = (0, 5);
match pair {
(mut y, 0) | (0, y) => println!("value is {y}"),
_ => println!("other"),
}
}
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
--> a1.rs:4:26
|
4 | (mut y, 0) | (0, y) => println!("value is {y}"),
| - ^ bound in different ways
| |
| first binding
warning: variable does not need to be mutable
--> a1.rs:4:10
|
4 | (mut y, 0) | (0, y) => println!("value is {y}"),
| ----^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` (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 E0409`.
The warning settles which direction this repair runs: the body only prints y, so the mut is not load-bearing here. But the instructive fix is the other direction, because it shows what to do when mutability is wanted - put mut on both bindings, and let the body use it. With the mode the same in both alternatives, the pattern compiles, and the body can reassign y no matter which position supplied it:
fn main() {
let pair: (i32, i32) = (0, 5);
match pair {
(mut y, 0) | (0, mut y) => { y += 1; println!("value is {y}"); },
_ => println!("other"),
}
let pair2: (i32, i32) = (7, 0);
match pair2 {
(mut y, 0) | (0, mut y) => { y += 1; println!("value is {y}"); },
_ => println!("other"),
}
}
value is 6
value is 8
The output is value is 6, then value is 8: each pair binds y from a different position, the body adds one either way, and the reassignment is legal on both paths because both bindings are mutable.
The second failure: mut inside one Some, plain inside the other
The same disagreement fits inside a single variant named twice. Some(mut y) | Some(y) binds the payload both times, in two modes - and the second alternative can never run, because the first already matches every Some. The compiler reports both facts:
fn main() {
let x: Option<i32> = Some(3);
match x {
Some(mut y) | Some(y) => println!("value is {y}"),
None => println!("no value"),
}
}
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
--> a2.rs:4:28
|
4 | Some(mut y) | Some(y) => println!("value is {y}"),
| - ^ bound in different ways
| |
| first binding
warning: unreachable pattern
--> a2.rs:4:23
|
4 | Some(mut y) | Some(y) => println!("value is {y}"),
| ----------- ^^^^^^^ no value can reach this
| |
| matches all the relevant values
|
= note: `#[warn(unreachable_patterns)]` (part of `#[warn(unused)]`) on by default
warning: variable does not need to be mutable
--> a2.rs:4:14
|
4 | Some(mut y) | Some(y) => println!("value is {y}"),
| ----^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` (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 E0409`.
Here neither direction of mode repair is the real fix, because the second alternative contributes nothing: it matches exactly what the first matches. Delete it, and the arm is one pattern with one binding, in whichever mode the body needs:
fn main() {
let x: Option<i32> = Some(3);
match x {
Some(y) => println!("value is {y}"),
None => println!("no value"),
}
}
value is 3
The output is value is 3. The lesson generalizes past this error: when an or-pattern names the same variant twice, ask what the second alternative adds before repairing its binding - if the answer is nothing, the alternative goes, and the mode question goes with it.
The third failure: mut on one struct field, plain on the other
With struct patterns the binding comes out of a named field, and the mode rides on the field binding. Here y comes from left as mut y in the first alternative and from right as plain y in the second - the same disagreement, spelled through two field names:
struct Pair { left: i32, right: i32 }
fn main() {
let p = Pair { left: 0, right: 5 };
match p {
Pair { left: mut y, right: 0 } | Pair { left: 0, right: y } => println!("value is {y}"),
_ => println!("other"),
}
}
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
--> a3.rs:5:65
|
5 | Pair { left: mut y, right: 0 } | Pair { left: 0, right: y } => println!("value is {y}"),
| - first binding ^ bound in different ways
warning: variable does not need to be mutable
--> a3.rs:5:22
|
5 | Pair { left: mut y, right: 0 } | Pair { left: 0, right: y } => println!("value is {y}"),
| ----^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` (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 E0409`.
The diagnostic lays both spans on one line here - the dash under the first field binding and the caret under the second - because the whole pattern fits on it. The repair is the first failure's, applied per field: mut on both field bindings, and a body that uses the mutability:
struct Pair { left: i32, right: i32 }
fn main() {
let p = Pair { left: 0, right: 5 };
match p {
Pair { left: mut y, right: 0 } | Pair { left: 0, right: mut y } => { y += 1; println!("value is {y}"); },
_ => println!("other"),
}
let q = Pair { left: 7, right: 0 };
match q {
Pair { left: mut y, right: 0 } | Pair { left: 0, right: mut y } => { y += 1; println!("value is {y}"); },
_ => println!("other"),
}
}
value is 6
value is 8
The output is value is 6, then value is 8: the first value binds y from right, the second from left, and the body treats them identically because the bindings are now identical in mode.
The fourth failure: ref against plain
This is the error index's own example shape. ref y binds a reference to the value in its position; plain y binds the value itself. The modes disagree - and because a reference is a different type from the value, the types disagree too, so this failure carries two errors:
fn main() {
let pair: (i32, i32) = (0, 5);
match pair {
(ref y, 0) | (0, y) => println!("value is {y}"),
_ => println!("other"),
}
}
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
--> a4.rs:4:26
|
4 | (ref y, 0) | (0, y) => println!("value is {y}"),
| - ^ bound in different ways
| |
| first binding
error[E0308]: mismatched types
--> a4.rs:4:26
|
3 | match pair {
| ---- this expression has type `(i32, i32)`
4 | (ref y, 0) | (0, y) => println!("value is {y}"),
| ----- ^ expected `&i32`, found `i32`
| |
| first introduced with type `&i32` here
|
= note: in the same arm, a binding must have the same type in all alternatives
help: consider adding `ref`
|
4 | (ref y, 0) | (0, ref y) => println!("value is {y}"),
| +++
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0308, E0409.
For more information about an error, try `rustc --explain E0308`.
The E0308 half even prescribes the repair: add ref to the second binding. That is the error index's prescription as well - use the same mode in both cases, generally by adding ref where it is missing. With ref in both alternatives, the modes agree, the types agree (&i32 on both paths), and both errors clear at once:
fn main() {
let pair: (i32, i32) = (0, 5);
match pair {
(ref y, 0) | (0, ref y) => println!("value is {y}"),
_ => println!("other"),
}
}
value is 5
The output is value is 5: y is a reference to the second position's value, and printing through the reference gives the value. Note what the body can no longer do - reassign the pair through y, or take ownership of the value - which is the trade the ref mode makes, and why the split-pattern repair exists for cases that need the value itself on one path.
The fifth failure: ref mut against ref
Reference bindings carry their own mutability, and it is part of the mode. ref mut y binds a &mut i32; ref y binds a &i32. The modes differ, the reference types differ in mutability, and the compiler again reports both disagreements:
fn main() {
let pair: (i32, i32) = (0, 5);
match pair {
(ref mut y, 0) | (0, ref y) => println!("value is {y}"),
_ => println!("other"),
}
}
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
--> a5.rs:4:34
|
4 | (ref mut y, 0) | (0, ref y) => println!("value is {y}"),
| - first binding ^ bound in different ways
error[E0308]: mismatched types
--> a5.rs:4:30
|
3 | match pair {
| ---- this expression has type `(i32, i32)`
4 | (ref mut y, 0) | (0, ref y) => println!("value is {y}"),
| --------- ^^^^^ types differ in mutability
| |
| first introduced with type `&mut i32` here
|
= note: expected mutable reference `&mut _`
found reference `&_`
= note: in the same arm, a binding must have the same type in all alternatives
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0308, E0409.
For more information about an error, try `rustc --explain E0308`.
The repair is to pick the reference the body needs and use it in both alternatives. A body that writes through the reference needs ref mut in both:
fn main() {
let mut pair: (i32, i32) = (0, 5);
match pair {
(ref mut y, 0) | (0, ref mut y) => { *y += 1; println!("value is {y}"); },
_ => println!("other"),
}
}
value is 6
The output is value is 6: y is a mutable reference to the second position, the body adds one through it, and the printed value reflects the write. Downgrading both to ref also repairs the error, for a body that only reads - the choice between the two repairs is the choice of what the body does, stated once, in both alternatives.
The sixth failure: the mismatch nested inside a tuple pattern
Nesting does not dilute the rule. Here the or-pattern sits in the first position of a tuple pattern, matching the first element against Some or None - and it binds y from the payload as mut y in one alternative and from the tuple's second element as plain y in the other:
fn main() {
let x: (Option<i32>, i32) = (Some(4), 9);
match x {
(Some(mut y), _) | (None, y) => println!("value is {y}"),
_ => println!("other"),
}
}
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
--> a6.rs:4:35
|
4 | (Some(mut y), _) | (None, y) => println!("value is {y}"),
| - first binding ^ bound in different ways
warning: unreachable pattern
--> a6.rs:5:9
|
4 | (Some(mut y), _) | (None, y) => println!("value is {y}"),
| ---------------------------- matches all the relevant values
5 | _ => println!("other"),
| ^ no value can reach this
|
= note: `#[warn(unreachable_patterns)]` (part of `#[warn(unused)]`) on by default
warning: variable does not need to be mutable
--> a6.rs:4:15
|
4 | (Some(mut y), _) | (None, y) => println!("value is {y}"),
| ----^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` (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 E0409`.
The two bindings do not even draw from the same place - one from inside the Option, one from the tuple's second slot - and the rule does not care: same name, one body, modes must match. Add mut to the second binding and the body may reassign y on both paths. The two alternatives between them cover every value, so the fixed version needs no wildcard arm:
fn main() {
let x: (Option<i32>, i32) = (Some(4), 9);
match x {
(Some(mut y), _) | (None, mut y) => { y += 1; println!("value is {y}"); },
}
let z: (Option<i32>, i32) = (None, 2);
match z {
(Some(mut y), _) | (None, mut y) => { y += 1; println!("value is {y}"); },
}
}
value is 5
value is 3
The output is value is 5, then value is 3: the first binds y from the payload and adds one, the second binds it from the tuple's second element and adds one - two different sources, one mode, one body.
The fixes in reach order
- Make the mode the same in every alternative - the error index's first prescription, and the repair for the first, third, fourth, fifth, and sixth failures. Add
mutorref(orref mut) to the alternatives that lack it when the body needs that mode; drop it from the alternatives that have it when the body does not - the "does not need to be mutable" warning marks the second case. - Delete a redundant alternative when one alternative already covers everything another would match - the second failure, where
Some(y)could never run next toSome(mut y). - Split the pattern into separate arms, each with its own body, when the cases genuinely want different modes - the error index's alternative prescription. Each arm's binding then keeps its own mode, and each body uses the variable the way that arm bound it.
Traps
y in one alternative and not at all in the other. There is no mode to compare, so the header is the missing-binding error, with its companion E0381 at the body's use:fn main() {
let x: Option<i32> = Some(7);
match x {
Some(y) | None => println!("value is {y}"),
_ => println!("unreachable"),
}
}
error[E0408]: variable `y` is not bound in all patterns
--> n1_missing.rs:4:19
|
4 | Some(y) | None => println!("value is {y}"),
| - ^^^^ pattern doesn't bind `y`
| |
| variable not in all patterns
warning: unreachable pattern
--> n1_missing.rs:5:9
|
4 | Some(y) | None => println!("value is {y}"),
| -------------- matches all the relevant values
5 | _ => println!("unreachable"),
| ^ no value can reach this
|
= note: `#[warn(unreachable_patterns)]` (part of `#[warn(unused)]`) on by default
error[E0381]: used binding `y` is possibly-uninitialized
--> n1_missing.rs:4:47
|
4 | Some(y) | None => println!("value is {y}"),
| - ^ `y` used here but it is possibly-uninitialized
| |
| binding initialized here in some conditions
| binding declared here but left uninitialized
error: aborting due to 2 previous errors; 1 warning emitted
Some errors have detailed explanations: E0381, E0408.
For more information about an error, try `rustc --explain E0381`.
The distinction is the first question to ask of any or-pattern error: is the variable present in every alternative? If not, the repair is E0408's - split the arm or bind it everywhere - and mode repairs do not apply.
Different types, same mode - E0308 alone. Both alternatives below bind y plainly, by value, in the same mode; what differs is the value's type, an i32 from the first position and a &str from the second. No E0409 appears:
fn main() {
let pair: (i32, &'static str) = (1, "a");
match pair {
(y, _) | (_, y) => println!("value is {y}"),
}
}
error[E0308]: mismatched types
--> n2_types.rs:4:22
|
3 | match pair {
| ---- this expression has type `(i32, &str)`
4 | (y, _) | (_, y) => println!("value is {y}"),
| - ^ expected `i32`, found `&str`
| |
| first introduced with type `i32` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.
The repair is not a mode repair: the two positions hold different kinds of value, so the cases need separate arms, each using its own type. Contrast the fourth failure, where the type difference was a side effect of the mode difference (ref against plain) and one repair cleared both errors.
The same mismatch in a let - three errors, one of them not about modes. Moving the first failure's pattern into a let does not isolate E0409: the unparenthesized or-pattern is not available at the top level of a let at all, and a pattern built from literals is refutable, which a let forbids - so the compiler reports the parentheses error and E0005 alongside the E0409:
fn main() {
let pair: (i32, i32) = (0, 5);
let (mut y, 0) | (0, y) = pair;
println!("value is {y}");
}
error: `let` bindings require top-level or-patterns in parentheses
--> a7_let.rs:3:9
|
3 | let (mut y, 0) | (0, y) = pair;
| ^^^^^^^^^^^^^^^^^^^
|
help: wrap the pattern in parentheses
|
3 | let ((mut y, 0) | (0, y)) = pair;
| + +
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
--> a7_let.rs:3:26
|
3 | let (mut y, 0) | (0, y) = pair;
| - ^ bound in different ways
| |
| first binding
error[E0005]: refutable pattern in local binding
--> a7_let.rs:3:9
|
3 | let (mut y, 0) | (0, y) = pair;
| ^^^^^^^^^^^^^^^^^^^ patterns `(i32::MIN..=-1_i32, i32::MIN..=-1_i32)`, `(i32::MIN..=-1_i32, 1_i32..=i32::MAX)`, `(1_i32..=i32::MAX, i32::MIN..=-1_i32)` and 1 more not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
= note: the matched value is of type `(i32, i32)`
help: you might want to use `let...else` to handle the variants that aren't matched
|
3 | let (mut y, 0) | (0, y) = pair else { todo!() };
| ++++++++++++++++
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0005, E0409.
For more information about an error, try `rustc --explain E0005`.
The practical reading: an or-pattern that picks a value out of two positions belongs in a match, not a let - the match is where refutable, alternative-driven binding is allowed to live, and inside it the mode rule is the only one of the three that remains.
Same mode in every alternative - compiles. Plain in both, from the traps' perspective, is the control case for the whole guide: the first failure with the stray mut removed:
fn main() {
let pair: (i32, i32) = (0, 5);
match pair {
(y, 0) | (0, y) => println!("value is {y}"),
_ => println!("other"),
}
}
value is 5
The output is value is 5. E0409 is never about or-patterns as such - it is about one variable arriving in two different modes, and here it arrives the same way on both paths.
Decision summary
- The header is E0409: every alternative binds the variable, but at least two bind it in different modes. The defect is the mode set, not the binding set.
- The two spans are the repair map: the dash span is the first binding, the caret span is the binding whose mode differs. One of the two changes mode, or the arm splits.
- A "does not need to be mutable" warning beside the E0409 says the body never uses the mutability - dropping
mutfrom the one alternative is then the whole repair. No warning means the body needs the mode - add it to the plain alternative instead. - An E0308 standing next to the E0409, on a
refcase, is the same defect's type shadow:refchanges the type as well as the mode, and making the modes agree clears both. - Neighbors ruled out by the header before applying this guide's repairs: E0408 for a variable missing from an alternative, E0308 alone for a type difference with the mode held the same, E0005 for the refutability problem that joins in when the pattern is moved into a
let. - Not an error at all: an or-pattern that binds the same variable in the same mode in every alternative - plain,
mut,ref, orref mutthroughout. Each compiles and runs.
Checklist
- Confirm the variable is present in every alternative first; if one alternative lacks it, the error is E0408 and the repair is different.
- Read the two spans together: first binding under the dash, differing binding under the caret.
- Decide what the body does with the variable - read it, reassign it, hold a reference, write through a reference - and set that one mode in every alternative.
- If an alternative is redundant - the same variant or value shape as another - delete it instead of repairing its mode.
- On a
refcase, expect the companion E0308 and check that it clears with the mode fix; if it remains, a real type difference is also present. - Keep or-patterns that select between positions in a
match; aletadds the parentheses and refutability rules on top of this one.
Related guides on this site
- E0408 Variable Not Bound in All Patterns Fix
- E0130 Patterns in Foreign Function Fix
- E0626 Borrow Across Yield Fix
- E0004 Non-Exhaustive Patterns Fix
Sources
- Rust, Error codes index: E0409 - the definition of the error: an "or" pattern was used where the variable bindings are not consistently bound across patterns - with the
(0, ref y) | (y, 0)example, the explanation thatyis bound by value in one case and by reference in the other, and the two prescriptions this guide follows: use the same mode in both cases, generallyreforref mutwhere not already used, or split the pattern. - The Rust Reference, Patterns - the or-pattern rules this guide rests on: a pattern
p | qis ill-formed if the same set of bindings is not introduced in both, if the types do not unify, or if the types or binding modes of same-named bindings do not unify - the third clause being this error, the first being E0408, and the second E0308.
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.