Skip to content

Commit ea5e3d2

Browse files
committed
Make moves explicit in doc examples
Had to remove the buffalo example. It was awkward to update for explicit moves.
1 parent d0ed13c commit ea5e3d2

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

doc/tutorial-tasks.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ use pipes::{stream, Port, Chan};
161161
162162
let (chan, port): (Chan<int>, Port<int>) = stream();
163163
164-
do spawn {
164+
do spawn |move chan| {
165165
let result = some_expensive_computation();
166166
chan.send(result);
167167
}
@@ -192,7 +192,7 @@ spawns the child task.
192192
# use pipes::{stream, Port, Chan};
193193
# fn some_expensive_computation() -> int { 42 }
194194
# let (chan, port) = stream();
195-
do spawn {
195+
do spawn |move chan| {
196196
let result = some_expensive_computation();
197197
chan.send(result);
198198
}
@@ -229,7 +229,7 @@ following program is ill-typed:
229229
# fn some_expensive_computation() -> int { 42 }
230230
let (chan, port) = stream();
231231
232-
do spawn {
232+
do spawn |move chan| {
233233
chan.send(some_expensive_computation());
234234
}
235235
@@ -253,7 +253,7 @@ let chan = SharedChan(move chan);
253253
for uint::range(0, 3) |init_val| {
254254
// Create a new channel handle to distribute to the child task
255255
let child_chan = chan.clone();
256-
do spawn {
256+
do spawn |move child_chan| {
257257
child_chan.send(some_expensive_computation(init_val));
258258
}
259259
}
@@ -283,10 +283,10 @@ might look like the example below.
283283
// Create a vector of ports, one for each child task
284284
let ports = do vec::from_fn(3) |init_val| {
285285
let (chan, port) = stream();
286-
do spawn {
286+
do spawn |move chan| {
287287
chan.send(some_expensive_computation(init_val));
288288
}
289-
port
289+
move port
290290
};
291291
292292
// Wait on each port, accumulating the results
@@ -398,13 +398,13 @@ before returning. Hence:
398398
# fn sleep_forever() { loop { task::yield() } }
399399
# do task::try {
400400
let (sender, receiver): (Chan<int>, Port<int>) = stream();
401-
do spawn { // Bidirectionally linked
401+
do spawn |move receiver| { // Bidirectionally linked
402402
// Wait for the supervised child task to exist.
403403
let message = receiver.recv();
404404
// Kill both it and the parent task.
405405
assert message != 42;
406406
}
407-
do try { // Unidirectionally linked
407+
do try |move sender| { // Unidirectionally linked
408408
sender.send(42);
409409
sleep_forever(); // Will get woken up by force
410410
}
@@ -505,7 +505,7 @@ Here is the code for the parent task:
505505
506506
let (from_child, to_child) = DuplexStream();
507507
508-
do spawn || {
508+
do spawn |move to_child| {
509509
stringifier(&to_child);
510510
};
511511

doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
18271827
for vec::each(vector) |element| {
18281828
accumulator.push(function(element));
18291829
}
1830-
return accumulator;
1830+
return (move accumulator);
18311831
}
18321832
~~~~
18331833

src/test/run-pass/issue-3668.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
struct P { child: Option<@mut P> }
2+
trait PTrait {
3+
fn getChildOption() -> Option<@P>;
4+
}
5+
6+
impl P: PTrait {
7+
fn getChildOption() -> Option<@P> {
8+
const childVal: @P = self.child.get();
9+
fail;
10+
}
11+
}
12+
13+
fn main() {}

src/test/run-pass/issue-3688-2.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn f(x:int) {
2+
const child: int = x + 1;
3+
}
4+
5+
fn main() {}

0 commit comments

Comments
 (0)