Skip to content

Commit 08e5cd4

Browse files
committed
Say that struct patterns can match union values
1 parent c6049ba commit 08e5cd4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/patterns.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ Reference patterns are always irrefutable.
597597
[_OuterAttribute_]: attributes.md
598598
[TUPLE_INDEX]: tokens.md#tuple-index
599599

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

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

@@ -642,7 +642,7 @@ match m {
642642
}
643643
```
644644

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

647647
```rust
648648
# struct Struct {
@@ -661,6 +661,8 @@ match struct_value {
661661
}
662662
```
663663

664+
A struct pattern used to match a union must specify exactly one field (see [Pattern matching on unions]).
665+
664666
The `ref` and/or `mut` _IDENTIFIER_ syntax matches any value and binds it to a variable with the same name as the given field.
665667

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

0 commit comments

Comments
 (0)