Skip to content

Commit

Permalink
Say that struct patterns can match union values
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheww committed Feb 27, 2024
1 parent c6049ba commit 08e5cd4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ Reference patterns are always irrefutable.
[_OuterAttribute_]: attributes.md
[TUPLE_INDEX]: tokens.md#tuple-index

Struct patterns match struct and enum values that match all criteria defined by its subpatterns.
They are also used to [destructure](#destructuring) a struct or enum value.
Struct patterns match struct, enum, and union values that match all criteria defined by its subpatterns.
They are also used to [destructure](#destructuring) a struct, enum, or union value.

On a struct pattern, the fields are referenced by name, index (in the case of tuple structs) or ignored by use of `..`:

Expand Down Expand Up @@ -642,7 +642,7 @@ match m {
}
```

If `..` is not used, it is required to match all fields:
If `..` is not used, a struct pattern used to match a struct is required to specify all fields:

```rust
# struct Struct {
Expand All @@ -661,6 +661,8 @@ match struct_value {
}
```

A struct pattern used to match a union must specify exactly one field (see [Pattern matching on unions]).

The `ref` and/or `mut` _IDENTIFIER_ syntax matches any value and binds it to a variable with the same name as the given field.

```rust
Expand Down Expand Up @@ -867,6 +869,7 @@ For example, `x @ A(..) | B(..)` will result in an error that `x` is not bound i
[literal expression]: expressions/literal-expr.md
[negating]: expressions/operator-expr.md#negation-operators
[path]: expressions/path-expr.md
[pattern matching on unions]: items/unions.md#pattern-matching-on-unions
[range expressions]: expressions/range-expr.md
[structs]: items/structs.md
[tuples]: types/tuple.md
Expand Down

0 comments on commit 08e5cd4

Please sign in to comment.