@@ -1465,6 +1465,14 @@ when evaluated in an _rvalue context_, it denotes the value held _in_ that memor
1465
1465
When an rvalue is used in lvalue context, a temporary un-named lvalue is created and used instead.
1466
1466
A temporary's lifetime equals the largest lifetime of any borrowed pointer that points to it.
1467
1467
1468
+ #### Moved and copied types
1469
+
1470
+ When a [ local variable] ( #memory-slots ) is used as an [ rvalue] ( #lvalues-rvalues-and-temporaries )
1471
+ the variable will either be [ moved] ( #move-expressions ) or [ copied] ( #copy-expressions ) ,
1472
+ depending on its type.
1473
+ For types that contain mutable fields or [ owning pointers] ( #owning-pointers ) , the variable is moved.
1474
+ All other types are copied.
1475
+
1468
1476
1469
1477
### Literal expressions
1470
1478
@@ -1787,7 +1795,7 @@ y.z <-> b.c;
1787
1795
An _ assignment expression_ consists of an [ lvalue] ( #lvalues-rvalues-and-temporaries ) expression followed by an
1788
1796
equals sign (` = ` ) and an [ rvalue] ( #lvalues-rvalues-and-temporaries ) expression.
1789
1797
1790
- Evaluating an assignment expression copies the expression on the right-hand side and stores it in the location on the left-hand side .
1798
+ Evaluating an assignment expression [ either copies or moves ] ( #moved-and-copied-types ) its right-hand operand to its left-hand operand .
1791
1799
1792
1800
~~~~
1793
1801
# let mut x = 0;
@@ -1860,7 +1868,7 @@ copy.
1860
1868
as are raw and borrowed pointers.
1861
1869
[ Owned boxes] ( #pointer-types ) , [ owned vectors] ( #vector-types ) and similar owned types are deep-copied.
1862
1870
1863
- Since the binary [ assignment operator] ( #assignment-expressions ) ` = ` performs a copy implicitly,
1871
+ Since the binary [ assignment operator] ( #assignment-expressions ) ` = ` performs a copy or move implicitly,
1864
1872
the unary copy operator is typically only used to cause an argument to a function to be copied and passed by value.
1865
1873
1866
1874
An example of a copy expression:
@@ -1884,13 +1892,17 @@ move_expr : "move" expr ;
1884
1892
~~~~~~~~
1885
1893
1886
1894
A _ unary move expression_ is similar to a [ unary copy] ( #unary-copy-expressions ) expression,
1887
- except that it can only be applied to an [ lvalue ] ( #lvalues-rvalues-and-temporaries ) ,
1895
+ except that it can only be applied to a [ local variable ] ( #memory-slots ) ,
1888
1896
and it performs a _ move_ on its operand, rather than a copy.
1889
1897
That is, the memory location denoted by its operand is de-initialized after evaluation,
1890
1898
and the resulting value is a shallow copy of the operand,
1891
1899
even if the operand is an [ owning type] ( #type-kinds ) .
1892
1900
1893
1901
1902
+ > ** Note:** In future versions of Rust, ` move ` may be removed as a separate operator;
1903
+ > moves are now [ automatically performed] ( #moved-and-copied-types ) for most cases ` move ` would be appropriate.
1904
+
1905
+
1894
1906
### Call expressions
1895
1907
1896
1908
~~~~~~~~ {.abnf .gram}
0 commit comments