|
25 | 25 |
|
26 | 26 | A *`match` expression* branches on a pattern. The exact form of matching that
|
27 | 27 | occurs depends on the [pattern]. A `match`
|
28 |
| -expression has a *head expression*, which is the value to compare to the |
29 |
| -patterns. The head expression and the patterns must have the same type. |
| 28 | +expression has a *scrutinee expression*, which is the value to compare to the |
| 29 | +patterns. The scrutinee expression and the patterns must have the same type. |
30 | 30 |
|
31 |
| -A `match` behaves differently depending on whether or not the head expression |
32 |
| -is a [place expression or value expression][place expression]. |
33 |
| -If the head expression is a [value expression], it is first evaluated into a |
34 |
| -temporary location, and the resulting value is sequentially compared to the |
| 31 | +A `match` behaves differently depending on whether or not the scrutinee |
| 32 | +expression is a [place expression or value expression][place expression]. |
| 33 | +If the scrutinee expression is a [value expression], it is first evaluated into |
| 34 | +a temporary location, and the resulting value is sequentially compared to the |
35 | 35 | patterns in the arms until a match is found. The first arm with a matching
|
36 | 36 | pattern is chosen as the branch target of the `match`, any variables bound by
|
37 | 37 | the pattern are assigned to local variables in the arm's block, and control
|
38 | 38 | enters the block.
|
39 | 39 |
|
40 |
| -When the head expression is a [place expression], the match does not allocate a |
41 |
| -temporary location; however, a by-value binding may copy or move from the |
42 |
| -memory location. |
| 40 | +When the scrutinee expression is a [place expression], the match does not |
| 41 | +allocate a temporary location; however, a by-value binding may copy or move |
| 42 | +from the memory location. |
43 | 43 | When possible, it is preferable to match on place expressions, as the lifetime
|
44 | 44 | of these matches inherits the lifetime of the place expression rather than being
|
45 | 45 | restricted to the inside of the match.
|
|
0 commit comments