From 5768c3098583d8d652271da97e2e6711f45f50c3 Mon Sep 17 00:00:00 2001 From: "Tim (Theemathas) Chirananthavat" Date: Fri, 21 Nov 2025 10:57:01 +0700 Subject: [PATCH] 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: