Skip to content

Commit ad55f9f

Browse files
authored
Merge pull request #496 from Centril/scrutinee
"head expression" => "scrutinee expression"
2 parents 692f694 + 28fa730 commit ad55f9f

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

src/expressions/loop-expr.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ while i < 10 {
7272
7373
A `while let` loop is semantically similar to a `while` loop but in place of a
7474
condition expression it expects the keyword `let` followed by a refutable
75-
pattern, an `=`, an expression and a block expression. If the value of the expression on
76-
the right hand side of the `=` matches the pattern, the loop body block executes then
77-
control returns to the pattern matching statement. Otherwise, the while
78-
expression completes.
75+
pattern, an `=`, a [scrutinee] expression and a block expression. If the value of
76+
the expression on the right hand side of the `=` matches the pattern, the loop
77+
body block executes then control returns to the pattern matching statement.
78+
Otherwise, the while expression completes.
7979

8080
```rust
8181
let mut x = vec![1, 2, 3];
@@ -274,3 +274,5 @@ expression `()`.
274274
[_Pattern_]: patterns.html
275275

276276
[LIFETIME_OR_LABEL]: tokens.html#lifetimes-and-loop-labels
277+
278+
[scrutinee]: glossary.html#scrutinee

src/expressions/match-expr.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
2626
A *`match` expression* branches on a pattern. The exact form of matching that
2727
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.
3030

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
3535
patterns in the arms until a match is found. The first arm with a matching
3636
pattern is chosen as the branch target of the `match`, any variables bound by
3737
the pattern are assigned to local variables in the arm's block, and control
3838
enters the block.
3939

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.
4343
When possible, it is preferable to match on place expressions, as the lifetime
4444
of these matches inherits the lifetime of the place expression rather than being
4545
restricted to the inside of the match.
@@ -144,3 +144,4 @@ expressions].
144144
[Range Pattern]: patterns.html#range-patterns
145145
[attributes on block expressions]: expressions/block-expr.html#attributes-on-block-expressions
146146
[binding mode]: patterns.html#binding-modes
147+
[scrutinee]: glossary.html#scrutinee

src/expressions/struct-expr.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ let base = Point3d {x: 1, y: 2, z: 3};
7171
Point3d {y: 0, z: 10, .. base};
7272
```
7373

74-
Struct expressions with curly braces can't be used directly in the head of a [loop] or an
75-
[if], [if let] or [match] expression. However, struct expressions can be in used in these
76-
situations if they are within another expression, for example inside
77-
[parentheses].
74+
Struct expressions with curly braces can't be used directly in a [loop] or [if]
75+
expression's head, or in the [scrutinee] of an [if let] or [match] expression.
76+
However, struct expressions can be in used in these situations if they are
77+
within another expression, for example inside [parentheses].
7878

7979
The field names can be decimal integer values to specify indices for constructing tuple
8080
structs. This can be used with base structs to fill out the remaining indices not
@@ -151,3 +151,4 @@ expressions].
151151
[struct]: items/structs.html
152152
[union]: items/unions.html
153153
[visible]: visibility-and-privacy.html
154+
[scrutinee]: glossary.html#scrutinee

src/glossary.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ Types that can be referred to by a path directly. Specifically [enums],
8080
Prelude, or The Rust Prelude, is a small collection of items - mostly traits - that are
8181
imported into every module of every crate. The traits in the prelude are pervasive.
8282

83+
### Scrutinee
84+
85+
A scrutinee is the expression that is matched on in `match` expressions and
86+
similar pattern matching constructs. For example, in `match x { A => 1, B => 2 }`,
87+
the expression `x` is the scrutinee.
88+
8389
### Size
8490

8591
The size of a value has two definitions.

src/patterns.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Patterns are used in:
6969

7070
Patterns can be used to *destructure* [structs], [enums], and [tuples].
7171
Destructuring breaks up a value into its component pieces. The syntax used is
72-
almost the same as when creating such values. In a pattern whose head
72+
almost the same as when creating such values. In a pattern whose [scrutinee]
7373
expression has a `struct`, `enum` or `tuple` type, a placeholder (`_`) stands
7474
in for a *single* data field, whereas a wildcard `..` stands in for *all* the
7575
remaining fields of a particular variant. When destructuring a data structure
@@ -676,3 +676,4 @@ refer to refutable constants or enum variants for enums with multiple variants.
676676
[literals]: expressions/literal-expr.html
677677
[structs]: items/structs.html
678678
[tuples]: types/tuple.html
679+
[scrutinee]: glossary.html#scrutinee

0 commit comments

Comments
 (0)