@@ -409,20 +409,35 @@ halfway between two floating point numbers.
409
409
> _ AssignmentExpression_ :\
410
410
>   ;  ; [ _ Expression_ ] ` = ` [ _ Expression_ ]
411
411
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
421
420
than promoting it to a temporary.
422
421
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
+
423
438
``` rust
424
- # let mut x = 0 ;
425
- # let y = 0 ;
439
+ let mut x = 0 ;
440
+ let y = 0 ;
426
441
x = y ;
427
442
```
428
443
@@ -506,13 +521,15 @@ dependency.
506
521
507
522
</div >
508
523
524
+ [ copies or moves ] : ../expressions.md#moved-and-copied-types
525
+ [ dropping ] : ../destructors.md
509
526
[ mutable ] : ../expressions.md#mutability
510
527
[ place expression ] : ../expressions.md#place-expressions-and-value-expressions
528
+ [ unit ] : ../types/tuple.md
511
529
[ value expression ] : ../expressions.md#place-expressions-and-value-expressions
512
530
[ temporary value ] : ../expressions.md#temporaries
513
531
[ this test ] : https://github.com/rust-lang/rust/blob/master/src/test/ui/expr/compound-assignment/eval-order.rs
514
532
[ float-float ] : https://github.com/rust-lang/rust/issues/15536
515
- [ `unit` type ] : ../types/tuple.md
516
533
[ Function pointer ] : ../types/function-pointer.md
517
534
[ Function item ] : ../types/function-item.md
518
535
0 commit comments