Skip to content

Commit 03366f0

Browse files
committed
---
yaml --- r: 36828 b: refs/heads/try2 c: 4676697 h: refs/heads/master v: v3
1 parent ed4813c commit 03366f0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: bb66fce3671f28a880ac7e8b2bfd8d76fe0eb4db
8+
refs/heads/try2: 46766974c73ff17a3b2cd4f2fb2cb06b7845ded4
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/doc/rust.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,14 @@ when evaluated in an _rvalue context_, it denotes the value held _in_ that memor
14651465
When an rvalue is used in lvalue context, a temporary un-named lvalue is created and used instead.
14661466
A temporary's lifetime equals the largest lifetime of any borrowed pointer that points to it.
14671467

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+
14681476

14691477
### Literal expressions
14701478

@@ -1787,7 +1795,7 @@ y.z <-> b.c;
17871795
An _assignment expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) expression followed by an
17881796
equals sign (`=`) and an [rvalue](#lvalues-rvalues-and-temporaries) expression.
17891797

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.
17911799

17921800
~~~~
17931801
# let mut x = 0;
@@ -1860,7 +1868,7 @@ copy.
18601868
as are raw and borrowed pointers.
18611869
[Owned boxes](#pointer-types), [owned vectors](#vector-types) and similar owned types are deep-copied.
18621870

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,
18641872
the unary copy operator is typically only used to cause an argument to a function to be copied and passed by value.
18651873

18661874
An example of a copy expression:
@@ -1884,13 +1892,17 @@ move_expr : "move" expr ;
18841892
~~~~~~~~
18851893

18861894
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),
18881896
and it performs a _move_ on its operand, rather than a copy.
18891897
That is, the memory location denoted by its operand is de-initialized after evaluation,
18901898
and the resulting value is a shallow copy of the operand,
18911899
even if the operand is an [owning type](#type-kinds).
18921900

18931901

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+
18941906
### Call expressions
18951907

18961908
~~~~~~~~ {.abnf .gram}

0 commit comments

Comments
 (0)