Skip to content

Commit e344b65

Browse files
committed
---
yaml --- r: 15618 b: refs/heads/try c: 03d9d62 h: refs/heads/master v: v3
1 parent 13b3445 commit e344b65

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: ea3362d12df1f90587d3452bd8f8e7836862118b
5+
refs/heads/try: 03d9d6287ba09bbfb7c0dfe8977e6629ea5066e1
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/doc/rust.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,10 +2155,30 @@ alt_pat : pat [ "to" pat ] ? [ "if" expr ] ;
21552155
An `alt` expression branches on a *pattern*. The exact form of matching that
21562156
occurs depends on the pattern. Patterns consist of some combination of
21572157
literals, destructured enum constructors, records and tuples, variable binding
2158-
specifications and placeholders (`_`). An `alt` expression has a *head
2158+
specifications, wildcards (`*`), and placeholders (`_`). An `alt` expression has a *head
21592159
expression*, which is the value to compare to the patterns. The type of the
21602160
patterns must equal the type of the head expression.
21612161

2162+
In a pattern whose head expression has an `enum` type, a placeholder (`_`) stands for a
2163+
*single* data field, whereas a wildcard `*` stands for *all* the fields of a particular
2164+
variant. For example:
2165+
2166+
~~~~
2167+
enum list<X> { nil, cons(X, @list<X>) }
2168+
2169+
let x: list<int> = cons(10, @cons(11, @nil));
2170+
2171+
alt x {
2172+
cons(_, @nil) { fail "singleton list"; }
2173+
cons(*) { ret; }
2174+
nil { fail "empty list"; }
2175+
}
2176+
~~~~
2177+
2178+
The first pattern matches lists constructed by applying `cons` to any head value, and a
2179+
tail value of `@nil`. The second pattern matches `any` list constructed with `cons`,
2180+
ignoring the values of its arguments.
2181+
21622182
To execute an `alt` expression, first the head expression is evaluated, then
21632183
its value is sequentially compared to the patterns in the arms until a match
21642184
is found. The first arm with a matching pattern is chosen as the branch target

0 commit comments

Comments
 (0)