File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -2150,9 +2150,19 @@ match x {
2150
2150
~~~~
2151
2151
2152
2152
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 ``` match ``` patterns to shadow 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
+
2156
2166
~~~~
2157
2167
# type options = {choose: bool, size: ~str};
2158
2168
# type player = {player: ~str, stats: (), options: options};
You can’t perform that action at this time.
0 commit comments