10
10
>   ;  ; | [ _ IdentifierPattern_ ] \
11
11
>   ;  ; | [ _ WildcardPattern_ ] \
12
12
>   ;  ; | [ _ RestPattern_ ] \
13
- >   ;  ; | [ _ ObsoleteRangePattern_ ] \
14
13
>   ;  ; | [ _ ReferencePattern_ ] \
15
14
>   ;  ; | [ _ StructPattern_ ] \
16
15
>   ;  ; | [ _ TupleStructPattern_ ] \
@@ -401,7 +400,14 @@ match tuple {
401
400
402
401
> ** <sup >Syntax</sup >** \
403
402
> _ RangePattern_ :\
404
- >   ;  ;   ;  ; _ RangePatternBound_ ` ..= ` _ RangePatternBound_ \
403
+ >   ;  ;   ;  ; _ InclusiveRangePattern_ \
404
+ >   ;  ; | _ HalfOpenRangePattern_ \
405
+ >   ;  ; | _ ObsoleteRangePattern_
406
+ >
407
+ > _ InclusiveRangePattern_ :\
408
+ >   ;  ;   ;  ; _ RangePatternBound_ ` ..= ` _ RangePatternBound_
409
+ >
410
+ > _ HalfOpenRangePattern_ :\
405
411
>   ;  ; | _ RangePatternBound_ ` .. `
406
412
>
407
413
> _ ObsoleteRangePattern_ :\
@@ -421,12 +427,14 @@ it matches all the values between and including both of its bounds. A range patt
421
427
half-open is written with a lower bound but not an upper bound, and matches any value equal to
422
428
or greater than the specified lower bound.
423
429
424
- For example, a pattern ` 'm'..='p' ` will match only the values ` 'm' ` , ` 'n' ` , ` 'o' ` , and ` 'p' ` . The
430
+ For example, a pattern ` 'm'..='p' ` will match only the values ` 'm' ` , ` 'n' ` , ` 'o' ` , and ` 'p' ` . For an integer the
425
431
pattern ` 1.. ` will match 9, or 9001, or 9007199254740991 (if it is of an appropriate size), but
426
- not 0 or negative numbers for signed integers. The bounds can be literals or paths that point
432
+ not 0, and not negative numbers for signed integers. The bounds can be literals or paths that point
427
433
to constant values.
428
434
429
- A pattern a ` ..= ` b must always have a &le ; b. It is an error to have a range pattern
435
+ A half-open range pattern in the style ` a.. ` cannot be used to match within the context of a slice.
436
+
437
+ A pattern ` a..=b ` must always have a &le ; b. It is an error to have a range pattern
430
438
` 10..=0 ` , for example.
431
439
432
440
The ` ... ` syntax is kept for backwards compatibility.
@@ -708,7 +716,11 @@ match int_reference {
708
716
>   ;  ; ` [ ` _ SlicePatternItems_ <sup >?</sup > ` ] `
709
717
>
710
718
> _ SlicePatternItems_ :\
711
- >   ;  ; [ _ Pattern_ ] \( ` , ` [ _ Pattern_ ] )<sup >\* </sup > ` , ` <sup >?</sup >
719
+ >   ;  ; _ InSlicePattern_ \( ` , ` _ InSlicePattern_ )<sup >\* </sup > ` , ` <sup >?</sup >
720
+ >
721
+ > _ InSlicePattern_ :\
722
+ >   ;  ;   ;  ; [ _ PatternWithoutRange_ ] \
723
+ >   ;  ; | [ _ ClosedRangePattern_ ]
712
724
713
725
Slice patterns can match both arrays of fixed size and slices of dynamic size.
714
726
``` rust
@@ -771,6 +783,7 @@ refer to refutable constants or enum variants for enums with multiple variants.
771
783
[ _PatternWithoutRange_ ] : #patterns
772
784
[ _QualifiedPathInExpression_ ] : paths.md#qualified-paths
773
785
[ _RangePattern_ ] : #range-patterns
786
+ [ _ClosedRangePattern_ ] : #range-patterns
774
787
[ _ReferencePattern_ ] : #reference-patterns
775
788
[ _RestPattern_ ] : #rest-patterns
776
789
[ _SlicePattern_ ] : #slice-patterns
0 commit comments