@@ -1124,13 +1124,16 @@ _exchange heap_, where their uniquely-owned nature allows tasks to
1124
1124
exchange them efficiently.
1125
1125
1126
1126
Because owned boxes are uniquely owned, copying them requires allocating
1127
- a new owned box and duplicating the contents. Copying owned boxes
1128
- is expensive so the compiler will complain if you do so without writing
1129
- the word ` copy ` .
1127
+ a new owned box and duplicating the contents.
1128
+ Instead, owned boxes are _ moved_ by default, transferring ownership,
1129
+ and deinitializing the previously owning variable.
1130
+ Any attempt to access a variable after the value has been moved out
1131
+ will result in a compile error.
1130
1132
1131
1133
~~~~
1132
1134
let x = ~10;
1133
- let y = x; // error: copying a non-implicitly copyable type
1135
+ // Move x to y, deinitializing x
1136
+ let y = x;
1134
1137
~~~~
1135
1138
1136
1139
If you really want to copy an owned box you must say so explicitly.
@@ -1143,19 +1146,6 @@ let z = *x + *y;
1143
1146
assert z == 20;
1144
1147
~~~~
1145
1148
1146
- This is where the 'move' operator comes in. It is similar to ` copy ` ,
1147
- but it de-initializes its source. Thus, the owned box can move from
1148
- ` x ` to ` y ` , without violating the constraint that it only has a single
1149
- owner (using assignment instead of the move operator would, in
1150
- principle, copy the box).
1151
-
1152
- ~~~~ {.xfail-test}
1153
- let x = ~10;
1154
- let y = move x;
1155
-
1156
- let z = *x + *y; // would cause an error: use of moved variable: `x`
1157
- ~~~~
1158
-
1159
1149
Owned boxes, when they do not contain any managed boxes, can be sent
1160
1150
to other tasks. The sending task will give up ownership of the box,
1161
1151
and won't be able to access it afterwards. The receiving task will
@@ -1360,7 +1350,7 @@ let your_crayons = ~[BananaMania, Beaver, Bittersweet];
1360
1350
let our_crayons = my_crayons + your_crayons;
1361
1351
1362
1352
// += will append to a vector, provided it lives in a mutable slot
1363
- let mut my_crayons = move my_crayons;
1353
+ let mut my_crayons = my_crayons;
1364
1354
my_crayons += your_crayons;
1365
1355
~~~~
1366
1356
@@ -1899,7 +1889,7 @@ fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
1899
1889
for vec::each(vector) |element| {
1900
1890
accumulator.push(function(element));
1901
1891
}
1902
- return (move accumulator) ;
1892
+ return accumulator;
1903
1893
}
1904
1894
~~~~
1905
1895
0 commit comments