Skip to content

Add grouped patterns. #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2018
Merged
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
33 changes: 27 additions & 6 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
>    | [_StructPattern_]\
>    | [_TupleStructPattern_]\
>    | [_TuplePattern_]\
>    | [_GroupedPattern_]\
>    | [_SlicePattern_]\
>    | [_PathPattern_]

Expand Down Expand Up @@ -582,6 +583,25 @@ They are also used to [destructure](#destructuring) a tuple.

This pattern is refutable when one of its subpatterns is refutable.

## Grouped patterns

> **<sup>Syntax</sup>**\
> _GroupedPattern_ :\
> &nbsp;&nbsp; `(` [_Pattern_] `)`

Enclosing a pattern in parentheses can be used to explicitly control the
precedence of compound patterns. For example, a reference pattern next to a
range pattern such as `&0..=5` is ambiguous and is not allowed, but can be
expressed with parentheses.

```rust
let int_reference = &3;
match int_reference {
&(0..=5) => (),
_ => (),
}
```

## Slice patterns

> **<sup>Syntax</sup>**\
Expand Down Expand Up @@ -633,17 +653,18 @@ Path patterns are irrefutable when they refer to structs or an enum variant when
has only one variant or a constant whose type is irrefutable. They are refutable when they
refer to refutable constants or enum variants for enums with multiple variants.

[_Pattern_]: #patterns
[_GroupedPattern_]: #grouped-patterns
[_IdentifierPattern_]: #identifier-patterns
[_LiteralPattern_]: #literal-patterns
[_WildcardPattern_]: #wildcard-pattern
[_PathPattern_]: #path-patterns
[_Pattern_]: #patterns
[_RangePattern_]: #range-patterns
[_ReferencePattern_]: #reference-patterns
[_IdentifierPattern_]: #identifier-patterns
[_TupleStructPattern_]: #tuple-struct-patterns
[_SlicePattern_]: #slice-patterns
[_StructPattern_]: #struct-patterns
[_TuplePattern_]: #tuple-patterns
[_SlicePattern_]: #slice-patterns
[_PathPattern_]: #path-patterns
[_TupleStructPattern_]: #tuple-struct-patterns
[_WildcardPattern_]: #wildcard-pattern

[`Copy`]: special-types-and-traits.html#copy
[IDENTIFIER]: identifiers.html
Expand Down