Skip to content

Commit 544d36b

Browse files
committed
manual: fixes to match expression examples and explanation.
1 parent 533cce8 commit 544d36b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

doc/rust.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ match_pat : pat [ ".." pat ] ? [ "if" expr ] ;
21862186

21872187
A `match` expression branches on a *pattern*. The exact form of matching that
21882188
occurs depends on the pattern. Patterns consist of some combination of
2189-
literals, destructured enum constructors, records and tuples, variable binding
2189+
literals, destructured enum constructors, structures, records and tuples, variable binding
21902190
specifications, wildcards (`*`), and placeholders (`_`). A `match` expression has a *head
21912191
expression*, which is the value to compare to the patterns. The type of the
21922192
patterns must equal the type of the head expression.
@@ -2196,19 +2196,19 @@ In a pattern whose head expression has an `enum` type, a placeholder (`_`) stand
21962196
variant. For example:
21972197

21982198
~~~~
2199-
enum list<X> { nil, cons(X, @list<X>) }
2199+
enum List<X> { Nil, Cons(X, @List<X>) }
22002200
2201-
let x: list<int> = cons(10, @cons(11, @nil));
2201+
let x: List<int> = Cons(10, @Cons(11, @Nil));
22022202
22032203
match x {
2204-
cons(_, @nil) => fail ~"singleton list",
2205-
cons(*) => return,
2206-
nil => fail ~"empty list"
2204+
Cons(_, @Nil) => fail ~"singleton list",
2205+
Cons(*) => return,
2206+
Nil => fail ~"empty list"
22072207
}
22082208
~~~~
22092209

2210-
The first pattern matches lists constructed by applying `cons` to any head value, and a
2211-
tail value of `@nil`. The second pattern matches `any` list constructed with `cons`,
2210+
The first pattern matches lists constructed by applying `Cons` to any head value, and a
2211+
tail value of `@Nil`. The second pattern matches _any_ list constructed with `Cons`,
22122212
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
22132213
`C` has exactly one argument, while the pattern `C(*)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
22142214

@@ -2225,18 +2225,18 @@ An example of an `match` expression:
22252225
# fn process_pair(a: int, b: int) { }
22262226
# fn process_ten() { }
22272227
2228-
enum list<X> { nil, cons(X, @list<X>) }
2228+
enum List<X> { Nil, Cons(X, @List<X>) }
22292229
2230-
let x: list<int> = cons(10, @cons(11, @nil));
2230+
let x: List<int> = Cons(10, @Cons(11, @Nil));
22312231
22322232
match x {
2233-
cons(a, @cons(b, _)) => {
2233+
Cons(a, @Cons(b, _)) => {
22342234
process_pair(a,b);
22352235
}
2236-
cons(10, _) => {
2236+
Cons(10, _) => {
22372237
process_ten();
22382238
}
2239-
nil => {
2239+
Nil => {
22402240
return;
22412241
}
22422242
_ => {
@@ -2245,7 +2245,7 @@ match x {
22452245
}
22462246
~~~~
22472247

2248-
Records can also be pattern-matched and their fields bound to variables.
2248+
Records and structures can also be pattern-matched and their fields bound to variables.
22492249
When matching fields of a record, the fields being matched are specified
22502250
first, then a placeholder (`_`) represents the remaining fields.
22512251

0 commit comments

Comments
 (0)