Skip to content

Commit cf93686

Browse files
theemathastraviscross
authored andcommitted
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 rust-lang/rust#149165
1 parent 93f3388 commit cf93686

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/patterns.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,12 @@ It is written as `..=` followed by the upper bound.
554554

555555
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.
556556

557-
r[patterns.range.constraint-less-than]
558-
The lower bound cannot be greater than the upper bound.
559-
That is, in `a..=b`, a ≤ b must be the case.
560-
For example, it is an error to have a range pattern `10..=0`.
557+
r[patterns.range.constraint-nonempty]
558+
A range pattern must match at least one possible value. In other words:
559+
560+
* 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.
561+
* 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`.
562+
* 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`.
561563

562564
r[patterns.range.bound]
563565
A bound is written as one of:

0 commit comments

Comments
 (0)