@@ -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
@@ -444,7 +459,7 @@ x = y;
444
459
The ` + ` , ` - ` , ` * ` , ` / ` , ` % ` , ` & ` , ` | ` , ` ^ ` , ` << ` , and ` >> ` operators may be
445
460
composed with the ` = ` operator. The expression ` place_exp OP= value ` is
446
461
equivalent to ` place_expr = place_expr OP val ` . For example, ` x = x + 1 ` may be
447
- written as ` x += 1 ` . Any such expression always has the [ ` unit ` type] .
462
+ written as ` x += 1 ` . Any such expression always has the [ ` unit ` type] [ unit ] .
448
463
These operators can all be overloaded using the trait with the same name as for
449
464
the normal operation followed by 'Assign', for example, ` std::ops::AddAssign `
450
465
is used to overload ` += ` . As with ` = ` , ` place_expr ` must be a [ place
@@ -456,11 +471,14 @@ x += 4;
456
471
assert_eq! (x , 14 );
457
472
```
458
473
474
+ [ copies or moves ] : ../expressions.md#moved-and-copied-types
475
+ [ dropping ] : ../destructors.md
476
+ [ mutable ] : ../expressions.md#mutability
459
477
[ place expression ] : ../expressions.md#place-expressions-and-value-expressions
478
+ [ unit ] : ../types/tuple.md
460
479
[ value expression ] : ../expressions.md#place-expressions-and-value-expressions
461
480
[ temporary value ] : ../expressions.md#temporaries
462
481
[ float-float ] : https://github.com/rust-lang/rust/issues/15536
463
- [ `unit` type ] : ../types/tuple.md
464
482
[ Function pointer ] : ../types/function-pointer.md
465
483
[ Function item ] : ../types/function-item.md
466
484
0 commit comments