Skip to content

Commit 95ab920

Browse files
MultisampledNightehuss
authored andcommitted
patterns: include new exclusive range patterns
See also rust-lang/rust#37854.
1 parent 5181795 commit 95ab920

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: src/patterns.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ match tuple {
397397
>    | _RangeToInclusivePattern_\
398398
>    | _ObsoleteRangePattern_
399399
>
400+
> _RangeExclusivePattern_ :\
401+
>       _RangePatternBound_ `..` _RangePatternBound_
402+
>
400403
> _RangeInclusivePattern_ :\
401404
>       _RangePatternBound_ `..=` _RangePatternBound_
402405
>
@@ -422,10 +425,11 @@ A bound on the left of the sigil is a *lower bound*.
422425
A bound on the right is an *upper bound*.
423426

424427
A range pattern with both a lower and upper bound will match all values between and including both of its bounds.
425-
It is written as its lower bound, followed by `..=`, followed by its upper bound.
428+
It is written as its lower bound, followed by `..` for end-exclusive or `..=` for end-inclusive, followed by its upper bound.
426429
The type of the range pattern is the type unification of its upper and lower bounds.
427430

428431
For example, a pattern `'m'..='p'` will match only the values `'m'`, `'n'`, `'o'`, and `'p'`.
432+
Similarly, `'m'..'p'` will match only `'m'`, `'n'` and `'o'`, specifically **not** including `'p'`.
429433

430434
The lower bound cannot be greater than the upper bound.
431435
That is, in `a..=b`, a ≤ b must be the case.
@@ -467,7 +471,7 @@ let valid_variable = match c {
467471

468472
# let ph = 10;
469473
println!("{}", match ph {
470-
0..=6 => "acid",
474+
0..7 => "acid",
471475
7 => "neutral",
472476
8..=14 => "base",
473477
_ => unreachable!(),
@@ -539,9 +543,6 @@ See [issue #41620](https://github.com/rust-lang/rust/issues/41620) for more info
539543

540544
> **Edition Differences**: Before the 2021 edition, range patterns with both a lower and upper bound may also be written using `...` in place of `..=`, with the same meaning.
541545
542-
> **Note**: Although range patterns use the same syntax as [range expressions], there are no exclusive range patterns.
543-
> That is, neither `x .. y` nor `.. x` are valid range patterns.
544-
545546
## Reference patterns
546547

547548
> **<sup>Syntax</sup>**\

0 commit comments

Comments
 (0)