E0005 Refutable Pattern in Local Binding Fix
Written December 2, 2026 · Tested with Rust 1.99.1 · 12 min read
- The rule underneath: a let has nowhere to put the other case
- How to read the diagnostic
- The first failure: the index example
- The same error on a Result, in a tuple, and with literals
Written December 2, 2026
Tested with Rust 1.99.1
What this guide is
Error E0005 means a pattern that can fail was used in a place that has no way to handle the failure. The error codes index puts it in one sentence: "Patterns used to bind names must be irrefutable, that is, they must guarantee that a name will be extracted in all cases."
In the shapes probed in this guide, E0005 fires for a plain let with an enum variant, a literal, or a range, and also for a function argument, a closure argument, and a for loop binding with an enum variant - the header changes its last words for each binding kind. The same variant pattern is legal in match, if let, while let, and let-else, because each of those has a place for the case that does not match. This guide shows the E0005 shapes, one neighboring shape that is not this error, and the repairs.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts, the file names are the bare names shown on the command line.
The rule underneath: a let has nowhere to put the other case
A let binding runs unconditionally. If its pattern names Some(y), there is no branch for None, so the compiler rejects the pattern before the program can run. The diagnostic note states the requirement directly: "let bindings require an "irrefutable pattern", like a struct or an enum with only one variant".
A tuple pattern on its own is irrefutable in the probed shape - let (a, b) = pair; for a (1, 2) pair compiled and ran, printing 1 2. Putting a refutable piece inside it makes the whole pattern refutable: let (Some(y), z) = pair; draws E0005, with the uncovered pattern named as (None, _).
How to read the diagnostic
The E0005 header names the binding kind: "refutable pattern in local binding" for a let, "refutable pattern in function argument", "refutable pattern in closure argument", and "refutable pattern in for loop binding" in the probed shapes. The span underlines the whole pattern and names the uncovered case - pattern None not covered, pattern Err(_) not covered, or, for a literal, the ranges on both sides of it.
For enum variant patterns in a let, the help proposes let-else: "you might want to use let...else to handle the variant that isn't matched", rewriting the line with an added else { todo!() }. For the literal and range shapes probed, the help instead proposes if let: "you might want to use if let to ignore the variants that aren't matched". In the function, closure, and for shapes probed, the transcript carries no help line - only the note naming the matched value's type.
No second error rode along in any probed shape: every failing program below drew exactly one error[E0005], except the array-length shape, which drew a different code instead.
The first failure: the index example
The index's erroneous example, verbatim:
#![allow(unused)]
fn main() {
let x = Some(1);
let Some(y) = x;
// error: refutable pattern in local binding: `None` not covered
}
error[E0005]: refutable pattern in local binding
--> fail_index.rs:4:5
|
4 | let Some(y) = x;
| ^^^^^^^ pattern `None` 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 `Option<i32>`
help: you might want to use `let...else` to handle the variant that isn't matched
|
4 | let Some(y) = x else { todo!() };
| ++++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0005`.
Exactly one E0005, and nothing else. The value really is Some(1) at run time, but that does not matter: the pattern has to cover every value the type can hold, not the one value this program happens to build.
The same error on a Result, in a tuple, and with literals
A Result variant in a let fails the same way. let Ok(v) = r; on a Result<u32, String> draws exactly one E0005, with the uncovered pattern named as Err(_) and the same let-else help:
fn main() {
let r: Result<u32, String> = Ok(7);
let Ok(v) = r;
println!("{}", v);
}
error[E0005]: refutable pattern in local binding
--> fail_let_ok.rs:3:9
|
3 | let Ok(v) = r;
| ^^^^^ pattern `Err(_)` not covered
A refutable piece inside a tuple pattern fails too, even though a plain tuple pattern does not. The uncovered pattern is the whole tuple with the failing piece replaced by its other case:
fn main() {
let pair = (Some(1), 2);
let (Some(y), z) = pair;
println!("{} {}", y, z);
}
error[E0005]: refutable pattern in local binding
--> fail_let_tuple_enum.rs:3:9
|
3 | let (Some(y), z) = pair;
| ^^^^^^^^^^^^ pattern `(None, _)` not covered
A literal in a let is refutable, because every other value fails to match it. let 3 = n; draws exactly one E0005, naming both uncovered ranges, and its help proposes if let rather than let-else:
fn main() {
let n = 3;
let 3 = n;
println!("{}", n);
}
error[E0005]: refutable pattern in local binding
--> fail_let_literal.rs:3:9
|
3 | let 3 = n;
| ^ patterns `i32::MIN..=2_i32` and `4_i32..=i32::MAX` not covered
A range behaves the same. let 1..=5 = n; on a u32 draws exactly one E0005, naming 0_u32 below the range and 6_u32..=u32::MAX above it, again with the if let help.
The same error in arguments and for loops
A function argument is a binding too, and it has no failure branch either. A refutable parameter pattern draws exactly one E0005, with the header switched to "function argument" and no help line in the probed shape:
fn show(Some(y): Option<u32>) {
println!("{}", y);
}
fn main() {
show(Some(4));
}
error[E0005]: refutable pattern in function argument
--> fail_fn_param.rs:1:9
|
1 | fn show(Some(y): Option<u32>) {
| ^^^^^^^ pattern `None` not covered
|
= note: the matched value is of type `Option<u32>`
A closure argument draws the same code with the header "refutable pattern in closure argument", for the probed shape |Some(y): Option<u32>| y.
A for loop binding draws it as well. The loop would have to skip an element that does not match, and a plain for has no syntax for that decision:
fn main() {
let xs = vec![Some(1), None, Some(3)];
for Some(y) in xs {
println!("{}", y);
}
}
error[E0005]: refutable pattern in `for` loop binding
--> fail_for_loop.rs:3:9
|
3 | for Some(y) in xs {
| ^^^^^^^ pattern `None` not covered
|
= note: the matched value is of type `Option<i32>`
The shape that is not this error
An array pattern with the wrong number of elements looks similar - a pattern the value cannot satisfy in a let - but it draws a different code. Matching a three-element array with a two-element pattern draws exactly one E0527, "pattern requires 2 elements but array has 3", and no E0005:
fn main() {
let xs = [1, 2, 3];
let [a, b] = xs;
println!("{} {}", a, b);
}
error[E0527]: pattern requires 2 elements but array has 3
--> fail_let_array_len.rs:3:9
|
3 | let [a, b] = xs;
| ^^^^^^ expected 3 elements
The fix there is a pattern with the right number of elements, or a rest pattern - not a match or a let-else for a missing variant.
Related guides
For a match that leaves a case out entirely, the neighboring code is E0004. For an array pattern with the wrong element count, the neighboring code is E0527.
The repairs
Every repair below gives the non-matching case somewhere to go: another match arm, an else, the body of a let-else block that leaves the scope, or a loop iteration that simply does not run the body.
Match on the value. This is the index page's own first repair, with an arm for each variant. It compiled and ran in the probed shape, printing 1 for the Some value and none for a None value run through the same code:
fn main() {
let x = Some(1);
match x {
Some(y) => { println!("{}", y); }
None => { println!("none"); }
}
let z: Option<u32> = None;
match z {
Some(y) => { println!("{}", y); }
None => { println!("none"); }
}
}
1
none
Use if let when only the matching case needs code. The pattern stays refutable, but if let supplies the missing branch - in the probed shape it compiled and ran, printing 1, and an added else arm printed nothing extra for that value:
fn main() {
let x = Some(1);
if let Some(y) = x {
println!("{}", y);
} else {
println!("none");
}
}
1
Use let-else when the code after the binding needs the extracted name. The else block must leave the scope - in the probed shapes it returns from main. With a Some(1) value it compiled and ran, printing 1; with a None value the same code printed none and returned:
fn main() {
let x = Some(1);
let Some(y) = x else {
println!("none");
return;
};
println!("{}", y);
}
1
Keep the loop variable plain and filter inside a for loop. Binding each element to a plain name is irrefutable, and an if let inside the body handles the elements that do not match. It compiled and ran in the probed shape, printing 1 and 3 and skipping the None element:
fn main() {
let xs = vec![Some(1), None, Some(3)];
for item in xs {
if let Some(y) = item {
println!("{}", y);
}
}
}
1
3
Take a plain argument and handle the pattern inside the function. The parameter binds the whole Option, and an if let in the body decides what to do with each case. It compiled and ran in the probed shape, printing 4 for Some(4) and printing nothing for None:
fn show(x: Option<u32>) {
if let Some(y) = x {
println!("{}", y);
}
}
fn main() {
show(Some(4));
show(None);
}
4
A guard belongs in a match, not in a let. The probed wildcard-and-guard shape compiled and ran, printing big 9 - the Some(y) if y > 5 arm took the value, with the plain Some and None arms behind it:
fn main() {
let x = Some(9);
match x {
Some(y) if y > 5 => { println!("big {}", y); }
Some(y) => { println!("small {}", y); }
None => { println!("none"); }
}
}
big 9
Two more refutable-tolerant shapes compiled and ran in the probes without becoming separate repairs above: while let Some(Some(y)) = xs.pop() over a vector of options printed 2 then 1, and the index page's combined match plus if let example compiled and ran with no output.
Fixes in reach order
First, read the header's last words. In the probed shapes they tell you which binding to move the pattern out of: a local binding, a function argument, a closure argument, or a for loop binding - the code is E0005 in all four.
Second, read the uncovered pattern on the span line. That is the case your replacement construct has to handle: None, Err(_), (None, _), or the values outside a literal or range.
Third, pick the construct that matches the code after it. Use let-else when later lines need the extracted name and the other case can leave the scope. Use if let when only the matching case needs code. Use match when both cases need code, or when a guard has to choose between arms.
Fourth, for arguments and loop bindings, move the pattern inside the body. Take the whole value as a plain parameter or loop variable, then apply match or if let inside - both forms compiled and ran in the probed shapes.
Last, check the code before reaching for this fix. In the probed shape, an array pattern with the wrong element count drew E0527, not E0005, and its fix is the pattern's shape, not a new construct around it.
Decision summary
E0005 fired in the probed shapes for a plain let naming an enum variant - the index example with Some (exactly one E0005), a Result with Ok (exactly one E0005), and a tuple containing Some (exactly one E0005) - for a let naming a literal 3 or a range 1..=5 (exactly one E0005 each), and for a refutable function argument, closure argument, and for loop binding (exactly one E0005 each, with the header naming the binding kind). It did not fire for the same pattern in match, if let, while let, or let-else, or for a plain tuple let, in the probed shapes. It also did not fire for an array pattern with the wrong number of elements, which drew exactly one E0527 instead. The repairs that compiled and ran were match with both arms (printing 1 then none across the two probed values), if let (printing 1), let-else (printing 1 for Some and none for None), if let inside a for loop over a plain loop variable (printing 1 and 3), a plain function argument with if let in the body (printing 4), and a guarded match (printing big 9).
Checklist
- E0005 is about where the pattern sits, in the probed shapes: a
let, a function or closure argument, or aforbinding has no branch for the case that does not match. - The span names the uncovered case -
None,Err(_),(None, _), or the values outside a literal or range; the repair has to give that exact case somewhere to go. - Enum variant patterns in a
letdrew thelet-else help; literal and range patterns in aletdrew theif lethelp, in the probed shapes. - A plain tuple pattern is irrefutable in the probed shape, but a tuple containing a variant pattern is not.
match,if let,while let, andlet-else all accept the refutable patterns probed, because each one supplies the other case.- An array pattern with the wrong element count is E0527 in the probed shape, not E0005 - check the code before choosing a fix.
Sources
- Rust error codes index, E0005 - patterns used to bind names must be irrefutable; the erroneous example binds
Some(y)in a plainleton anOption, and the page showsmatchandif letas the ways to deal with the possibility of failure. - Rust error codes index, E0527 - the code drawn in the probed shape by an array pattern that requires a different number of elements than the array has.
- Rust error codes index, E0004 - the neighboring code for a
matchwhose patterns do not cover every case.
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.