You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/rust.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -2174,17 +2174,6 @@ Records and structures can also be pattern-matched and their fields bound to var
2174
2174
When matching fields of a record,
2175
2175
the fields being matched are specified first,
2176
2176
then a placeholder (`_`) represents the remaining fields.
2177
-
2178
-
A pattern that's just a variable binding,
2179
-
like `Nil` in the previous answer,
2180
-
could either refer to an enum variant that's in scope,
2181
-
or bind a new variable.
2182
-
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2183
-
For example, wherever ```List``` is in scope,
2184
-
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2185
-
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2186
-
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2187
-
and local variables with lower-case letters.
2188
2177
2189
2178
~~~~
2190
2179
# type options = {choose: bool, size: ~str};
@@ -2217,6 +2206,17 @@ fn main() {
2217
2206
}
2218
2207
~~~~
2219
2208
2209
+
A pattern that's just a variable binding,
2210
+
like `Nil` in the previous answer,
2211
+
could either refer to an enum variant that's in scope,
2212
+
or bind a new variable.
2213
+
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2214
+
For example, wherever ```List``` is in scope,
2215
+
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2216
+
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2217
+
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2218
+
and local variables with lower-case letters.
2219
+
2220
2220
Multiple match patterns may be joined with the `|` operator. A
2221
2221
range of values may be specified with `..`. For example:
0 commit comments