|
10 | 10 | > | [_StructPattern_]\
|
11 | 11 | > | [_TupleStructPattern_]\
|
12 | 12 | > | [_TuplePattern_]\
|
| 13 | +> | [_GroupedPattern_]\ |
13 | 14 | > | [_SlicePattern_]\
|
14 | 15 | > | [_PathPattern_]
|
15 | 16 |
|
@@ -582,6 +583,25 @@ They are also used to [destructure](#destructuring) a tuple.
|
582 | 583 |
|
583 | 584 | This pattern is refutable when one of its subpatterns is refutable.
|
584 | 585 |
|
| 586 | +## Grouped patterns |
| 587 | + |
| 588 | +> **<sup>Syntax</sup>**\ |
| 589 | +> _GroupedPattern_ :\ |
| 590 | +> `(` [_Pattern_] `)` |
| 591 | +
|
| 592 | +Enclosing a pattern in parentheses can be used to explicitly control the |
| 593 | +precedence of compound patterns. For example, a reference pattern next to a |
| 594 | +range pattern such as `&0..=5` is ambiguous and is not allowed, but can be |
| 595 | +expressed with parentheses. |
| 596 | + |
| 597 | +```rust |
| 598 | +let int_reference = &3; |
| 599 | +match int_reference { |
| 600 | + &(0..=5) => (), |
| 601 | + _ => (), |
| 602 | +} |
| 603 | +``` |
| 604 | + |
585 | 605 | ## Slice patterns
|
586 | 606 |
|
587 | 607 | > **<sup>Syntax</sup>**\
|
@@ -633,17 +653,18 @@ Path patterns are irrefutable when they refer to structs or an enum variant when
|
633 | 653 | has only one variant or a constant whose type is irrefutable. They are refutable when they
|
634 | 654 | refer to refutable constants or enum variants for enums with multiple variants.
|
635 | 655 |
|
636 |
| -[_Pattern_]: #patterns |
| 656 | +[_GroupedPattern_]: #grouped-patterns |
| 657 | +[_IdentifierPattern_]: #identifier-patterns |
637 | 658 | [_LiteralPattern_]: #literal-patterns
|
638 |
| -[_WildcardPattern_]: #wildcard-pattern |
| 659 | +[_PathPattern_]: #path-patterns |
| 660 | +[_Pattern_]: #patterns |
639 | 661 | [_RangePattern_]: #range-patterns
|
640 | 662 | [_ReferencePattern_]: #reference-patterns
|
641 |
| -[_IdentifierPattern_]: #identifier-patterns |
642 |
| -[_TupleStructPattern_]: #tuple-struct-patterns |
| 663 | +[_SlicePattern_]: #slice-patterns |
643 | 664 | [_StructPattern_]: #struct-patterns
|
644 | 665 | [_TuplePattern_]: #tuple-patterns
|
645 |
| -[_SlicePattern_]: #slice-patterns |
646 |
| -[_PathPattern_]: #path-patterns |
| 666 | +[_TupleStructPattern_]: #tuple-struct-patterns |
| 667 | +[_WildcardPattern_]: #wildcard-pattern |
647 | 668 |
|
648 | 669 | [`Copy`]: special-types-and-traits.html#copy
|
649 | 670 | [IDENTIFIER]: identifiers.html
|
|
0 commit comments