Skip to content

Commit 301182e

Browse files
committed
Referencify Assignment Operator
I'm being wish-washy with expression/operand in the syntax section. I'm not quite sure if we should call them `place operands` everywhere.
1 parent 9360ab9 commit 301182e

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/expressions/operator-expr.md

+29-12
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,35 @@ halfway between two floating point numbers.
409409
> _AssignmentExpression_ :\
410410
>    [_Expression_] `=` [_Expression_]
411411
412-
An _assignment expression_ consists of a [place expression] followed by an
413-
equals sign (`=`) and a [value expression]. Such an expression always has
414-
the [`unit` type].
415-
416-
Evaluating an assignment expression [drops](../destructors.md) the left-hand
417-
operand, unless it's an uninitialized local variable or field of a local variable,
418-
and [either copies or moves](../expressions.md#moved-and-copied-types) its
419-
right-hand operand to its left-hand operand. The left-hand operand must be a
420-
place expression: using a value expression results in a compiler error, rather
412+
An *assignment expression* moves a value into a specified place.
413+
414+
An assignment expression consists of a [mutable] [place expression], the
415+
*assigned place operand*, followed by an equals sign (`=`) and a [value
416+
expression], the *assigned value operand*.
417+
418+
Unlike other place operands, the assigned place operand must be a place
419+
expression. Attempting to use a value expression is a compiler error rather
421420
than promoting it to a temporary.
422421

422+
Evaluating assignment expressions begins by evaluating its operands. The
423+
assigned value operand is evaluated first, followed by the assigned place
424+
operand.
425+
426+
> **Note**: This is different than other expressions in that the right operand
427+
> is evaluated before the left one.
428+
429+
It then has the effect of first [dropping] the value at the assigned place,
430+
unless the place is an uninitialized local variable or field of a local
431+
variable. Next it either [copies or moves] the assigned value to the assigned
432+
place.
433+
434+
An assignment expression always produces [the unit value][unit].
435+
436+
Example:
437+
423438
```rust
424-
# let mut x = 0;
425-
# let y = 0;
439+
let mut x = 0;
440+
let y = 0;
426441
x = y;
427442
```
428443

@@ -506,13 +521,15 @@ dependency.
506521

507522
</div>
508523

524+
[copies or moves]: ../expressions.md#moved-and-copied-types
525+
[dropping]: ../destructors.md
509526
[mutable]: ../expressions.md#mutability
510527
[place expression]: ../expressions.md#place-expressions-and-value-expressions
528+
[unit]: ../types/tuple.md
511529
[value expression]: ../expressions.md#place-expressions-and-value-expressions
512530
[temporary value]: ../expressions.md#temporaries
513531
[this test]: https://github.com/rust-lang/rust/blob/master/src/test/ui/expr/compound-assignment/eval-order.rs
514532
[float-float]: https://github.com/rust-lang/rust/issues/15536
515-
[`unit` type]: ../types/tuple.md
516533
[Function pointer]: ../types/function-pointer.md
517534
[Function item]: ../types/function-item.md
518535

0 commit comments

Comments
 (0)