Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording here seemed little strange to me. Does this make sense? Obviously range patterns that are outside the range of the scrutinee won't match the value at all.

Suggested change
A range pattern must match at least one possible value. In other words:
A range pattern must be able to match at least one possible value. In other words:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote it this way to be consistent with the other lines in this section, for example:

The exclusive range pattern matches all values from the lower bound up to, but not including the upper bound.


* 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:
Expand Down