Skip to content

Commit

Permalink
Update with slice pattern restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Sep 16, 2021
1 parent da75d92 commit 76ed5db
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
>    | [_IdentifierPattern_]\
>    | [_WildcardPattern_]\
>    | [_RestPattern_]\
>    | [_ObsoleteRangePattern_]\
>    | [_ReferencePattern_]\
>    | [_StructPattern_]\
>    | [_TupleStructPattern_]\
Expand Down Expand Up @@ -401,7 +400,14 @@ match tuple {

> **<sup>Syntax</sup>**\
> _RangePattern_ :\
> &nbsp;&nbsp; &nbsp;&nbsp; _RangePatternBound_ `..=` _RangePatternBound_\
> &nbsp;&nbsp; &nbsp;&nbsp; _InclusiveRangePattern_\
> &nbsp;&nbsp; | _HalfOpenRangePattern_\
> &nbsp;&nbsp; | _ObsoleteRangePattern_
>
> _InclusiveRangePattern_ :\
> &nbsp;&nbsp; &nbsp;&nbsp; _RangePatternBound_ `..=` _RangePatternBound_
>
> _HalfOpenRangePattern_ :\
> &nbsp;&nbsp; | _RangePatternBound_ `..`
>
> _ObsoleteRangePattern_ :\
Expand All @@ -421,12 +427,14 @@ it matches all the values between and including both of its bounds. A range patt
half-open is written with a lower bound but not an upper bound, and matches any value equal to
or greater than the specified lower bound.

For example, a pattern `'m'..='p'` will match only the values `'m'`, `'n'`, `'o'`, and `'p'`. The
For example, a pattern `'m'..='p'` will match only the values `'m'`, `'n'`, `'o'`, and `'p'`. For an integer the
pattern `1..` will match 9, or 9001, or 9007199254740991 (if it is of an appropriate size), but
not 0 or negative numbers for signed integers. The bounds can be literals or paths that point
not 0, and not negative numbers for signed integers. The bounds can be literals or paths that point
to constant values.

A pattern a `..=` b must always have a &le; b. It is an error to have a range pattern
A half-open range pattern in the style `a..` cannot be used to match within the context of a slice.

A pattern `a..=b` must always have a &le; b. It is an error to have a range pattern
`10..=0`, for example.

The `...` syntax is kept for backwards compatibility.
Expand Down Expand Up @@ -734,6 +742,10 @@ is irrefutable. When matching a slice, it is irrefutable only in the form with
a single `..` [rest pattern](#rest-patterns) or [identifier
pattern](#identifier-patterns) with the `..` rest pattern as a subpattern.

Within a slice, a half-open range pattern like `a..` must be enclosed in parentheses,
as in `(a..)`, to clarify it is intended to match a single value.
A future version of Rust may give the non-parenthesized version an alternate meaning.

## Path patterns

> **<sup>Syntax</sup>**\
Expand Down

0 comments on commit 76ed5db

Please sign in to comment.