Skip to content

Commit cafdf23

Browse files
committed
---
yaml --- r: 38791 b: refs/heads/incoming c: 0ef75a6 h: refs/heads/master i: 38789: d475548 38787: 6c0392f 38783: a113211 v: v3
1 parent e326259 commit cafdf23

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: decbbaa182e488926d4ff7078a6be0b7dda45a41
9+
refs/heads/incoming: 0ef75a69659fa16604b0001afaa63f00fe18c36e
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/rust.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,9 +2150,21 @@ match x {
21502150
~~~~
21512151

21522152
Records and structures can also be pattern-matched and their fields bound to variables.
2153-
When matching fields of a record, the fields being matched are specified
2154-
first, then a placeholder (`_`) represents the remaining fields.
2155-
2153+
When matching fields of a record,
2154+
the fields being matched are specified first,
2155+
then a placeholder (`_`) represents the remaining fields.
2156+
2157+
A pattern that's just a variable binding,
2158+
like `Nil` in the previous answer,
2159+
could either refer to an enum variant that's in scope,
2160+
or bind a new variable.
2161+
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2162+
For example, wherever ```List``` is in scope,
2163+
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2164+
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2165+
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2166+
and local variables with lower-case letters.
2167+
21562168
~~~~
21572169
# type options = {choose: bool, size: ~str};
21582170
# type player = {player: ~str, stats: (), options: options};

0 commit comments

Comments
 (0)