Skip to content

Commit b5f75d7

Browse files
ezyangadrientetar
authored andcommitted
---
yaml --- r: 97805 b: refs/heads/snap-stage3 c: e33b1da h: refs/heads/master i: 97803: 9318e63 v: v3
1 parent 718b461 commit b5f75d7

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: b2cac497e8989fb6d26c1f20441e8354950bbcc3
4+
refs/heads/snap-stage3: e33b1dabd35685e586f85f3e53783e31871bc5b7
55
refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/rust.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,12 +2893,21 @@ tail value of `~Nil`. The second pattern matches _any_ list constructed with `Co
28932893
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
28942894
`C` has exactly one argument, while the pattern `C(..)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
28952895

2896-
To execute an `match` expression, first the head expression is evaluated, then
2897-
its value is sequentially compared to the patterns in the arms until a match
2896+
A `match` behaves differently depending on whether or not the head expression
2897+
is an [lvalue or an rvalue](#lvalues-rvalues-and-temporaries).
2898+
If the head expression is an rvalue, it is
2899+
first evaluated into a temporary location, and the resulting value
2900+
is sequentially compared to the patterns in the arms until a match
28982901
is found. The first arm with a matching pattern is chosen as the branch target
28992902
of the `match`, any variables bound by the pattern are assigned to local
29002903
variables in the arm's block, and control enters the block.
29012904

2905+
When the head expression is an lvalue, the match does not allocate a
2906+
temporary location (however, a by-value binding may copy or move from
2907+
the lvalue). When possible, it is preferable to match on lvalues, as the
2908+
lifetime of these matches inherits the lifetime of the lvalue, rather
2909+
than being restricted to the inside of the match.
2910+
29022911
An example of an `match` expression:
29032912

29042913
~~~~
@@ -2932,6 +2941,15 @@ This can be changed to bind to a reference by
29322941
using the ```ref``` keyword,
29332942
or to a mutable reference using ```ref mut```.
29342943

2944+
Patterns can also dereference pointers by using the ``&``,
2945+
``~`` or ``@`` symbols, as appropriate. For example, these two matches
2946+
on ``x: &int`` are equivalent:
2947+
2948+
~~~~
2949+
match *x { 0 => "zero", _ => "some" }
2950+
match x { &0 => "zero", _ => "some" }
2951+
~~~~
2952+
29352953
A pattern that's just an identifier,
29362954
like `Nil` in the previous answer,
29372955
could either refer to an enum variant that's in scope,

0 commit comments

Comments
 (0)