Skip to content

"head expression" => "scrutinee expression" #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/expressions/loop-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ while i < 10 {
> &nbsp;&nbsp; `while` `let` [_Pattern_] `=` [_Expression_]<sub>except struct expression</sub>
> [_BlockExpression_]

[scrutinee]: glossary.html#scrutinee

A `while let` loop is semantically similar to a `while` loop but in place of a
condition expression it expects the keyword `let` followed by a refutable
pattern, an `=`, an expression and a block expression. If the value of the expression on
the right hand side of the `=` matches the pattern, the loop body block executes then
control returns to the pattern matching statement. Otherwise, the while
expression completes.
pattern, an `=`, a [scrutinee] expression and a block expression. If the value of
the expression on the right hand side of the `=` matches the pattern, the loop
body block executes then control returns to the pattern matching statement.
Otherwise, the while expression completes.

```rust
let mut x = vec![1, 2, 3];
Expand Down
20 changes: 11 additions & 9 deletions src/expressions/match-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@
> _MatchArmGuard_ :\
> &nbsp;&nbsp; `if` [_Expression_]

[scrutinee]: glossary.html#scrutinee

A *`match` expression* branches on a pattern. The exact form of matching that
occurs depends on the [pattern]. A `match`
expression has a *head expression*, which is the value to compare to the
patterns. The head expression and the patterns must have the same type.
expression has a *[scrutinee] expression*, which is the value to compare to the
patterns. The scrutinee expression and the patterns must have the same type.

A `match` behaves differently depending on whether or not the head expression
is a [place expression or value expression][place expression].
If the head expression is a [value expression], it is first evaluated into a
temporary location, and the resulting value is sequentially compared to the
A `match` behaves differently depending on whether or not the scrutinee
expression is a [place expression or value expression][place expression].
If the scrutinee expression is a [value expression], it is first evaluated into
a temporary location, and the resulting value is sequentially compared to the
patterns in the arms until a match is found. The first arm with a matching
pattern is chosen as the branch target of the `match`, any variables bound by
the pattern are assigned to local variables in the arm's block, and control
enters the block.

When the head expression is a [place expression], the match does not allocate a
temporary location; however, a by-value binding may copy or move from the
memory location.
When the scrutinee expression is a [place expression], the match does not
allocate a temporary location; however, a by-value binding may copy or move
from the memory location.
When possible, it is preferable to match on place expressions, as the lifetime
of these matches inherits the lifetime of the place expression rather than being
restricted to the inside of the match.
Expand Down
10 changes: 6 additions & 4 deletions src/expressions/struct-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ let base = Point3d {x: 1, y: 2, z: 3};
Point3d {y: 0, z: 10, .. base};
```

Struct expressions with curly braces can't be used directly in the head of a [loop] or an
[if], [if let] or [match] expression. However, struct expressions can be in used in these
situations if they are within another expression, for example inside
[parentheses].
[scrutinee]: glossary.html#scrutinee

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

The field names can be decimal integer values to specify indices for constructing tuple
structs. This can be used with base structs to fill out the remaining indices not
Expand Down
6 changes: 6 additions & 0 deletions src/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ Types that can be referred to by a path directly. Specifically [enums],
Prelude, or The Rust Prelude, is a small collection of items - mostly traits - that are
imported into every module of every crate. The traits in the prelude are pervasive.

### Scrutinee

A scrutinee is the expression that is matched on in `match` expressions and
similar pattern matching constructs. For example, in `match x { A => 1, B => 2 }`,
the expression `x` is the scrutinee.

### Size

The size of a value has two definitions.
Expand Down
4 changes: 3 additions & 1 deletion src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ Patterns are used in:

## Destructuring

[scrutinee]: glossary.html#scrutinee

Patterns can be used to *destructure* [structs], [enums], and [tuples].
Destructuring breaks up a value into its component pieces. The syntax used is
almost the same as when creating such values. In a pattern whose head
almost the same as when creating such values. In a pattern whose [scrutinee]
expression has a `struct`, `enum` or `tuple` type, a placeholder (`_`) stands
in for a *single* data field, whereas a wildcard `..` stands in for *all* the
remaining fields of a particular variant. When destructuring a data structure
Expand Down