Skip to content

Commit e46de53

Browse files
committed
Moved the matching structs example next to the prose talking about struct matching
1 parent 67d421d commit e46de53

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

doc/rust.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,17 +2174,6 @@ Records and structures can also be pattern-matched and their fields bound to var
21742174
When matching fields of a record,
21752175
the fields being matched are specified first,
21762176
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.
21882177

21892178
~~~~
21902179
# type options = {choose: bool, size: ~str};
@@ -2217,6 +2206,17 @@ fn main() {
22172206
}
22182207
~~~~
22192208

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+
22202220
Multiple match patterns may be joined with the `|` operator. A
22212221
range of values may be specified with `..`. For example:
22222222

0 commit comments

Comments
 (0)