Skip to content
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

fix grammar in Expressions #1057

Merged
merged 1 commit into from
Jul 5, 2021
Merged
Changes from all 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
20 changes: 10 additions & 10 deletions src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ assert_eq!(
## Place Expressions and Value Expressions

Expressions are divided into two main categories: place expressions and
value expressions. Likewise within each expression, operands may occur
value expressions. Likewise, within each expression, operands may occur
in either place context or value context. The evaluation of an expression
depends both on its own category and the context it occurs within.

Expand Down Expand Up @@ -173,7 +173,7 @@ The following contexts are *place expression* contexts:
When a place expression is evaluated in a value expression context, or is bound
by value in a pattern, it denotes the value held _in_ that memory location. If
the type of that value implements [`Copy`], then the value will be copied. In
the remaining situations if that type is [`Sized`], then it may be possible to
the remaining situations, if that type is [`Sized`], then it may be possible to
move the value. Only the following place expressions may be moved out of:

* [Variables] which are not currently borrowed.
Expand All @@ -183,46 +183,46 @@ move the value. Only the following place expressions may be moved out of:
* The result of [dereferencing][deref] an expression with type [`Box<T>`] and
that can also be moved out of.

Moving out of a place expression that evaluates to a local variable, the
When moving out of a place expression that evaluates to a local variable, the
location is deinitialized and cannot be read from again until it is
reinitialized. In all other cases, trying to use a place expression in a value
expression context is an error.

### Mutability

For a place expression to be [assigned][assign] to, mutably [borrowed][borrow],
[implicitly mutably borrowed], or bound to a pattern containing `ref mut` it
[implicitly mutably borrowed], or bound to a pattern containing `ref mut`, it
must be _mutable_. We call these *mutable place expressions*. In contrast,
other place expressions are called *immutable place expressions*.

The following expressions can be mutable place expression contexts:

* Mutable [variables], which are not currently borrowed.
* Mutable [variables] which are not currently borrowed.
* [Mutable `static` items].
* [Temporary values].
* [Fields][field], this evaluates the subexpression in a mutable place
* [Fields][field]: this evaluates the subexpression in a mutable place
expression context.
* [Dereferences][deref] of a `*mut T` pointer.
* Dereference of a variable, or field of a variable, with type `&mut T`. Note:
This is an exception to the requirement of the next rule.
* Dereferences of a type that implements `DerefMut`, this then requires that
* Dereferences of a type that implements `DerefMut`: this then requires that
the value being dereferenced is evaluated is a mutable place expression context.
* [Array indexing] of a type that implements `IndexMut`, this
* [Array indexing] of a type that implements `IndexMut`: this
then evaluates the value being indexed, but not the index, in mutable place
expression context.

### Temporaries

When using a value expression in most place expression contexts, a temporary
unnamed memory location is created initialized to that value and the expression
unnamed memory location is created and initialized to that value. The expression
evaluates to that location instead, except if [promoted] to a `static`. The
[drop scope] of the temporary is usually the end of the enclosing statement.

### Implicit Borrows

Certain expressions will treat an expression as a place expression by implicitly
borrowing it. For example, it is possible to compare two unsized [slices][slice] for
equality directly, because the `==` operator implicitly borrows it's operands:
equality directly, because the `==` operator implicitly borrows its operands:

```rust
# let c = [1, 2, 3];
Expand Down