From cf93686c375fab178342d7e6393c5e7deadc44a7 Mon Sep 17 00:00:00 2001 From: "Tim (Theemathas) Chirananthavat" Date: Fri, 21 Nov 2025 10:57:01 +0700 Subject: [PATCH 1/2] Specify that range patterns must be nonempty. This changes the reference to match the behavior of the compiler, based on my empirical testing. See also https://github.com/rust-lang/rust/issues/149165 --- src/patterns.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/patterns.md b/src/patterns.md index 6c00126fc0..15bd5ad6dd 100644 --- a/src/patterns.md +++ b/src/patterns.md @@ -554,10 +554,12 @@ It is written as `..=` followed by the upper bound. For example, `..=10` will match any integer less than or equal to 10, such as 10, 1, 0, and for signed integer types, all negative values. -r[patterns.range.constraint-less-than] -The lower bound cannot be greater than the upper bound. -That is, in `a..=b`, a ≤ b must be the case. -For example, it is an error to have a range pattern `10..=0`. +r[patterns.range.constraint-nonempty] +A range pattern must match at least one possible value. In other words: + +* In `a..=b`, a ≤ b must be the case. For example, it is an error to have a range pattern `10..=0`, but `10..=10` is allowed. +* In `a..b`, a < b must be the case. For example, it is an error to have a range pattern `10..0` or `10..10`. +* In `..b`, b must not be the smallest value of its type. For example, it is an error to have a range pattern `..-128i8` or `..f64::NEG_INFINITY`. r[patterns.range.bound] A bound is written as one of: From de7d8878e616b5e404826ef6bb0b8a48d38517e6 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 9 Dec 2025 21:23:01 +0000 Subject: [PATCH 2/2] Revise wording on `constraint-nonempty` Let's revise the wording to avoid a possible ambiguity about what we're matching against. --- src/patterns.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.md b/src/patterns.md index 15bd5ad6dd..2433c2545b 100644 --- a/src/patterns.md +++ b/src/patterns.md @@ -555,7 +555,7 @@ It is written as `..=` followed by the upper bound. For example, `..=10` will match any integer less than or equal to 10, such as 10, 1, 0, and for signed integer types, all negative values. r[patterns.range.constraint-nonempty] -A range pattern must match at least one possible value. In other words: +A range pattern must be nonempty; it must span at least one value in the set of possible values for its type. In other words: * In `a..=b`, a ≤ b must be the case. For example, it is an error to have a range pattern `10..=0`, but `10..=10` is allowed. * In `a..b`, a < b must be the case. For example, it is an error to have a range pattern `10..0` or `10..10`.