E0030 Empty Range Pattern Fix
Written December 2, 2026 · Tested with Rust 1.99.1 · 13 min read
- The rule underneath: an inclusive range pattern must be able to match something
- How to read the diagnostic
- The first failure: the index example
- The same error one step past equal, with other endpoint types, and outside a match
Written December 2, 2026
Tested with Rust 1.99.1
What this guide is
Error E0030 means an inclusive range pattern was written with its lower bound greater than its upper bound. The error codes index puts the reason plainly: when matching against a range, the compiler verifies that the range is non-empty, and because range patterns include both endpoints, the start of the range has to be less than or equal to the end.
In the shapes probed in this guide, E0030 fires for a reversed inclusive range over integers, characters, single bytes, negative integers, and floats, in a match, in a let, and in an if let. It does not fire for an exclusive range written backwards or with equal endpoints - that shape draws a different code, E0579 - and it does not fire for a reversed string range, which draws E0029 because its endpoints are the wrong type before their order is ever considered. This guide shows the E0030 shapes, the neighboring shapes that are 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: an inclusive range pattern must be able to match something
An inclusive range pattern, written with ..=, includes both of its endpoints. That makes the smallest legal inclusive range the one whose two endpoints are equal: it matches exactly that one value. The moment the lower bound moves one step past the upper bound, no value can satisfy the pattern, and the compiler refuses it at compile time instead of letting a match arm sit in the code that can never fire.
That is the whole fix in most cases. The endpoints were written in the wrong order: swap them, and the range covers the values between them. Where the test is not really a pattern at all - a value checked against a range computed or written once - the same check can be written with contains in an if or a guard, in the probed shapes.
How to read the diagnostic
The E0030 header is the same in every probed shape: "lower bound for range pattern must be less than or equal to upper bound". The span underlines the whole range, from the lower bound through the upper bound, and the note under it reads "lower bound larger than upper bound". There is no per-endpoint note and no help block in the probed shapes - the diagnostic names the range and the problem, and the order of the two endpoints is the thing to change.
The count follows the ranges, in the probed shapes: a program with one reversed inclusive range drew exactly one error[E0030], and a program with two reversed inclusive ranges in two arms drew exactly two, one per range, with "aborting due to 2 previous errors". No other error code rode along in any probed E0030 shape.
The first failure: the index example
The index's erroneous example, verbatim. The first arm, 1 ..= 1, is the page's own note on the boundary - an equal-endpoint range is legal, albeit pointless as the page says - and it is the second arm that aborts compilation:
#![allow(unused)]
fn main() {
match 5u32 {
// This range is ok, albeit pointless.
1 ..= 1 => {}
// This range is empty, and the compiler can tell.
1000 ..= 5 => {}
}
}
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> fail_index.rs:7:5
|
7 | 1000 ..= 5 => {}
| ^^^^^^^^^^ lower bound larger than upper bound
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0030`.
Exactly one E0030, and nothing else. The endpoints are the right type - both are integers - and a range between them is meaningful; only their order is wrong.
The same error one step past equal, with other endpoint types, and outside a match
Distance does not matter, in the probed shapes. The smallest possible violation, 6 ..= 5 on a u32 - the lower bound one step past the upper bound - draws exactly one E0030 with the same header and note as the index example:
fn main() {
match 5u32 {
6 ..= 5 => { println!("in"); }
_ => { println!("out"); }
}
}
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> fail_adjacent.rs:3:9
|
3 | 6 ..= 5 => { println!("in"); }
| ^^^^^^^ lower bound larger than upper bound
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0030`.
A reversed char range fails the same way. 'z' ..= 'a' on a char draws exactly one E0030:
fn main() {
let c = 'm';
match c {
'z' ..= 'a' => { println!("in"); }
_ => { println!("out"); }
}
}
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> fail_char_reversed.rs:4:9
|
4 | 'z' ..= 'a' => { println!("in"); }
| ^^^^^^^^^^^ lower bound larger than upper bound
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0030`.
The same held for the other endpoint types probed, each drawing exactly one E0030 with the same header and note: a reversed single-byte range, b'z' ..= b'a' on a u8; a reversed negative range, -1 ..= -5 on an i32, where the lower bound is the endpoint closer to zero; and a reversed float range, 2.0 ..= 1.0 on an f64:
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> fail_float_reversed.rs:4:9
|
4 | 2.0 ..= 1.0 => { println!("in"); }
| ^^^^^^^^^^^ lower bound larger than upper bound
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0030`.
The float case is worth separating from its neighbor: a float range in the right order is accepted, as the E0029 guide's probes showed, so floats are not refused as endpoints - a reversed float range is refused for its order, like every other reversed inclusive range probed.
The pattern's position does not save it. A reversed inclusive range in a let - let 1000 ..= 5 = v; - draws exactly one E0030 in the probed shape:
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> fail_let.rs:3:9
|
3 | let 1000 ..= 5 = v;
| ^^^^^^^^^^ lower bound larger than upper bound
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0030`.
A reversed inclusive range in an if let draws exactly one E0030 in the probed shape as well, with the same header and note.
The shapes that are not this error
An exclusive range written backwards looks like the same mistake - an empty range in a pattern - but the operator is different, and so is the code. 10 .. 5 on a u32 draws exactly one E0579, "lower bound for range pattern must be less than upper bound", and no E0030:
fn main() {
match 5u32 {
10 .. 5 => { println!("in"); }
_ => { println!("out"); }
}
}
error[E0579]: lower bound for range pattern must be less than upper bound
--> fail_exclusive_reversed.rs:3:9
|
3 | 10 .. 5 => { println!("in"); }
| ^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0579`.
The wording difference carries the rule difference, in the probed shapes: the inclusive form allows equal endpoints ("less than or equal to"), the exclusive form does not ("less than"). So an exclusive range with equal endpoints, 5 .. 5, also draws exactly one E0579 in the probed shape - it is empty too, because the upper endpoint is excluded - while the inclusive 1 ..= 1 in the index example is legal. The fix is the same in spirit - put the endpoints in an order that leaves something in the range - but check the code before reaching for this guide's fix, because the boundary case differs: equal endpoints repair an inclusive range and do not repair an exclusive one.
A reversed string range is not this error either. "world" ..= "hello" draws exactly one E0029, "only char and numeric types are allowed in range patterns", in the probed shape: the endpoints' type is refused before their order is considered, and its fix is a guard or an if, not a swap.
Related guides
For a range pattern whose endpoints are of a type range patterns do not accept, the neighboring code is E0029.
The repairs
Every repair below starts from the same observation: the range as written can match nothing, so either the endpoints move into an order that can match, or the check moves out of the pattern into ordinary code.
Swap the endpoints. This is the direct fix for the index shape. With the endpoints in the other order, 5 ..= 1000 compiled and ran in the probed shape, printing in for both values run through the same code - the endpoint value 5 and the middle value 500:
fn main() {
match 5u32 {
5 ..= 1000 => { println!("in"); }
_ => { println!("out"); }
}
match 500u32 {
5 ..= 1000 => { println!("in"); }
_ => { println!("out"); }
}
}
in
in
Keep equal endpoints when the range is meant to hold one value. The index example's first arm is the shape: 1 ..= 1 compiled and ran in the probed shape, printing one for the value 1. An inclusive range whose endpoints meet is not empty - it is a one-value range, and writing it as the single literal pattern says the same thing more plainly when only one value is meant.
Test the value with contains when the check is not really a pattern. An inclusive range value can test membership directly: in the probed shape, (5 ..= 1000).contains(&v) in an if compiled and ran, printing in for 500 and out for 3:
fn main() {
let v = 500u32;
if (5 ..= 1000).contains(&v) { println!("in"); } else { println!("out"); }
let w = 3u32;
if (5 ..= 1000).contains(&w) { println!("in"); } else { println!("out"); }
}
in
out
The contains form really does discriminate - the same code printed out for the value below the range - and it keeps the endpoints in their natural low-to-high order in ordinary expression position, where a reversed range is a runtime value that matches nothing rather than a compile error; the endpoints still have to be written in the right order for the test to mean anything.
Use the same contains test in a match guard when the match stays. In the probed shape, a guard testing (5 ..= 1000).contains(&x) compiled and ran, printing in for the value 500:
fn main() {
let v = 500u32;
match v {
x if (5 ..= 1000).contains(&x) => { println!("in"); }
_ => { println!("out"); }
}
}
in
Swap a reversed char range the same way. In the probed shape, 'a' ..= 'z' on a char compiled and ran, printing lower for 'm' - the reversed 'z' ..= 'a' from the failing shapes with its endpoints put back in order.
One more accepted shape compiled and ran in the probes without becoming a separate repair above: a non-empty exclusive range at its boundary, 5 .. 6 on a u32, printed in for the value 5 - the exclusive form is legal when its lower bound is strictly below its upper bound, in the probed shape.
Fixes in reach order
First, read the operator. In the probed shapes, E0030 is the inclusive form's code: the header says the lower bound must be "less than or equal to" the upper bound. An exclusive range written backwards or with equal endpoints drew E0579 instead, whose header drops the "or equal to" - check which code you have before choosing a fix, because equal endpoints are legal only in the inclusive form, in the probed shapes.
Second, swap the two endpoints. In the probed shapes that is the whole repair for a reversed inclusive range over integers, characters, single bytes, negative integers, and floats: the range then covers the values between them.
Third, if the endpoints were meant to meet at one value, keep them equal in the inclusive form - 1 ..= 1 is legal in the probed shape - or write the single value as its own pattern.
Fourth, if the check is a membership test rather than a pattern, move it into an if or a guard with contains, keeping the endpoints in low-to-high order.
Last, check the endpoints' type before blaming their order. In the probed shape, a reversed string range drew E0029, not E0030 - its fix is a guard comparing the strings, not a swap.
Decision summary
E0030 fired in the probed shapes for an inclusive range pattern whose lower bound is greater than its upper bound: the index example 1000 ..= 5 (exactly one E0030), the one-step violation 6 ..= 5 (exactly one E0030), a reversed char range (exactly one E0030), a reversed single-byte range (exactly one E0030), a reversed negative range (exactly one E0030), a reversed float range (exactly one E0030), a reversed inclusive range in a let (exactly one E0030), and the same shape in an if let (exactly one E0030). Two reversed inclusive ranges in one program drew exactly two E0030 errors, one per range. It did not fire for an exclusive range written backwards or with equal endpoints, which drew exactly one E0579 each in the probed shapes, or for a reversed string range, which drew exactly one E0029. The repairs that compiled and ran were swapping the endpoints (printing in for both probed values), an equal-endpoint inclusive range (printing one), a contains test in an if (printing in for the in-range value and out for the value below the range), the same test in a guard (printing in), and a swapped char range (printing lower).
Checklist
- E0030 is about the endpoints' order, in the probed shapes: an inclusive range pattern's lower bound must be less than or equal to its upper bound.
- Equal endpoints are legal in the inclusive form, in the probed shape:
1 ..= 1matches exactly one value. - The exclusive form has a different code and a stricter rule, in the probed shapes: a backwards or equal-endpoint exclusive range drew E0579, whose header requires the lower bound to be less than the upper bound.
- Distance does not matter, in the probed shapes:
6 ..= 5, one step past equal, drew E0030 just as1000 ..= 5did. - The error count follows the ranges, in the probed shapes: two reversed inclusive ranges drew two E0030 errors.
- A reversed range over the wrong endpoint type is a different error, in the probed shape: a reversed string range drew E0029 - check the code before choosing a fix.
Sources
- Rust error codes index, E0030 - when matching against a range, the compiler verifies that the range is non-empty; range patterns include both endpoints, so the start of the range must be less than or equal to the end; the erroneous example matches a u32 against
1000 ..= 5beside a legal1 ..= 1. - Rust error codes index, E0029 - the neighboring code for a range pattern whose endpoints are not char or numeric values, drawn in the probed shape by a reversed string range.
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.