Skip to content

Commit e1580f6

Browse files
committed
auto merge of #11868 : bytbox/rust/remove-do, r=alexcrichton
Fixes #10815.
2 parents 87004db + a6867e2 commit e1580f6

File tree

168 files changed

+843
-1398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+843
-1398
lines changed

doc/guide-conditions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@ use std::task;
261261
fn main() {
262262
263263
// Isolate failure within a subtask.
264-
let result = do task::try {
264+
let result = task::try(proc() {
265265
266266
// The protected logic.
267267
let pairs = read_int_pairs();
268268
for &(a,b) in pairs.iter() {
269269
println!("{:4.4d}, {:4.4d}", a, b);
270270
}
271271
272-
};
272+
});
273273
if result.is_err() {
274274
println!("parsing failed");
275275
}

doc/guide-pointers.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ struct Point {
221221

222222
fn main() {
223223
let a = Point { x: 10, y: 20 };
224-
do spawn {
224+
spawn(proc() {
225225
println!("{}", a.x);
226-
}
226+
});
227227
}
228228
~~~
229229

@@ -238,9 +238,9 @@ struct Point {
238238

239239
fn main() {
240240
let a = ~Point { x: 10, y: 20 };
241-
do spawn {
241+
spawn(proc() {
242242
println!("{}", a.x);
243-
}
243+
});
244244
}
245245
~~~
246246

doc/guide-runtime.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ extern mod green;
236236
237237
#[start]
238238
fn start(argc: int, argv: **u8) -> int {
239-
do green::start(argc, argv) {
239+
green::start(argc, argv, proc() {
240240
main();
241-
}
241+
})
242242
}
243243
244244
fn main() {}

doc/guide-tasks.md

+21-26
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ spawn(print_message);
7777
7878
// Print something more profound in a different task using a lambda expression
7979
spawn(proc() println!("I am also running in a different task!") );
80-
81-
// The canonical way to spawn is using `do` notation
82-
do spawn {
83-
println!("I too am running in a different task!");
84-
}
8580
~~~~
8681

8782
In Rust, there is nothing special about creating tasks: a task is not a
@@ -103,10 +98,10 @@ an environment that it carries across tasks.
10398
// Generate some state locally
10499
let child_task_number = generate_task_number();
105100
106-
do spawn {
101+
spawn(proc() {
107102
// Capture it in the remote task
108103
println!("I am child number {}", child_task_number);
109-
}
104+
});
110105
~~~
111106

112107
## Communication
@@ -132,10 +127,10 @@ concurrently:
132127
133128
let (port, chan): (Port<int>, Chan<int>) = Chan::new();
134129
135-
do spawn || {
130+
spawn(proc() {
136131
let result = some_expensive_computation();
137132
chan.send(result);
138-
}
133+
});
139134
140135
some_other_expensive_computation();
141136
let result = port.recv();
@@ -160,10 +155,10 @@ spawns the child task.
160155
# use std::task::spawn;
161156
# fn some_expensive_computation() -> int { 42 }
162157
# let (port, chan) = Chan::new();
163-
do spawn || {
158+
spawn(proc() {
164159
let result = some_expensive_computation();
165160
chan.send(result);
166-
}
161+
});
167162
~~~~
168163

169164
Notice that the creation of the task closure transfers `chan` to the child
@@ -195,15 +190,15 @@ of tasks? The following program is ill-typed:
195190
# fn some_expensive_computation() -> int { 42 }
196191
let (port, chan) = Chan::new();
197192
198-
do spawn {
193+
spawn(proc() {
199194
chan.send(some_expensive_computation());
200-
}
195+
});
201196
202197
// ERROR! The previous spawn statement already owns the channel,
203198
// so the compiler will not allow it to be captured again
204-
do spawn {
199+
spawn(proc() {
205200
chan.send(some_expensive_computation());
206-
}
201+
});
207202
~~~
208203

209204
Instead we can use a `SharedChan`, a type that allows a single
@@ -217,9 +212,9 @@ let (port, chan) = SharedChan::new();
217212
for init_val in range(0u, 3) {
218213
// Create a new channel handle to distribute to the child task
219214
let child_chan = chan.clone();
220-
do spawn {
215+
spawn(proc() {
221216
child_chan.send(some_expensive_computation(init_val));
222-
}
217+
});
223218
}
224219
225220
let result = port.recv() + port.recv() + port.recv();
@@ -247,9 +242,9 @@ might look like the example below.
247242
// Create a vector of ports, one for each child task
248243
let ports = vec::from_fn(3, |init_val| {
249244
let (port, chan) = Chan::new();
250-
do spawn {
245+
spawn(proc() {
251246
chan.send(some_expensive_computation(init_val));
252-
}
247+
});
253248
port
254249
});
255250
@@ -296,7 +291,7 @@ fn partial_sum(start: uint) -> f64 {
296291
}
297292
298293
fn main() {
299-
let mut futures = vec::from_fn(1000, |ind| do extra::future::Future::spawn { partial_sum(ind) });
294+
let mut futures = vec::from_fn(1000, |ind| extra::future::Future::spawn( proc() { partial_sum(ind) }));
300295
301296
let mut final_res = 0f64;
302297
for ft in futures.mut_iter() {
@@ -339,11 +334,11 @@ fn main() {
339334
let (port, chan) = Chan::new();
340335
chan.send(numbers_arc.clone());
341336
342-
do spawn {
337+
spawn(proc() {
343338
let local_arc : Arc<~[f64]> = port.recv();
344339
let task_numbers = local_arc.get();
345340
println!("{}-norm = {}", num, pnorm(task_numbers, num));
346-
}
341+
});
347342
}
348343
}
349344
~~~
@@ -417,13 +412,13 @@ termination with an error).
417412
# use std::task;
418413
# fn some_condition() -> bool { false }
419414
# fn calculate_result() -> int { 0 }
420-
let result: Result<int, ()> = do task::try {
415+
let result: Result<int, ()> = task::try(proc() {
421416
if some_condition() {
422417
calculate_result()
423418
} else {
424419
fail!("oops!");
425420
}
426-
};
421+
});
427422
assert!(result.is_err());
428423
~~~
429424

@@ -502,9 +497,9 @@ Here is the code for the parent task:
502497
503498
let (from_child, to_child) = DuplexStream::new();
504499
505-
do spawn {
500+
spawn(proc() {
506501
stringifier(&to_child);
507-
};
502+
});
508503
509504
from_child.send(22);
510505
assert!(from_child.recv() == ~"22");

doc/rust.md

-46
Original file line numberDiff line numberDiff line change
@@ -2751,52 +2751,6 @@ but must enclose it.
27512751

27522752
A `loop` expression is only permitted in the body of a loop.
27532753

2754-
### Do expressions
2755-
2756-
~~~~ {.ebnf .gram}
2757-
do_expr : "do" expr [ '|' ident_list '|' ] ? '{' block '}' ;
2758-
~~~~
2759-
2760-
A _do expression_ provides a more-familiar block syntax
2761-
for invoking a function and passing it a newly-created a procedure.
2762-
2763-
The optional `ident_list` and `block` provided in a `do` expression are parsed
2764-
as though they constitute a procedure expression;
2765-
if the `ident_list` is missing, an empty `ident_list` is implied.
2766-
2767-
The procedure expression is then provided as a _trailing argument_
2768-
to the outermost [call](#call-expressions) or
2769-
[method call](#method-call-expressions) expression
2770-
in the `expr` following `do`.
2771-
If the `expr` is a [path expression](#path-expressions), it is parsed as though it is a call expression.
2772-
If the `expr` is a [field expression](#field-expressions), it is parsed as though it is a method call expression.
2773-
2774-
In this example, both calls to `f` are equivalent:
2775-
2776-
~~~~
2777-
# fn f(f: proc(int)) { }
2778-
# fn g(i: int) { }
2779-
2780-
f(proc(j) { g(j) });
2781-
2782-
do f |j| {
2783-
g(j);
2784-
}
2785-
~~~~
2786-
2787-
In this example, both calls to the (binary) function `k` are equivalent:
2788-
2789-
~~~~
2790-
# fn k(x:int, f: proc(int)) { }
2791-
# fn l(i: int) { }
2792-
2793-
k(3, proc(j) { l(j) });
2794-
2795-
do k(3) |j| {
2796-
l(j);
2797-
}
2798-
~~~~
2799-
28002754
### For expressions
28012755

28022756
~~~~ {.ebnf .gram}

doc/tutorial.md

+9-37
Original file line numberDiff line numberDiff line change
@@ -1796,48 +1796,20 @@ call_it(proc(n) {
17961796
});
17971797
~~~~
17981798
1799-
This is such a useful pattern that Rust has a special form of function
1800-
call for these functions.
1801-
1802-
~~~~
1803-
# fn call_it(op: proc(v: int)) { }
1804-
do call_it() |n| {
1805-
println!("{}", n);
1806-
}
1807-
~~~~
1808-
1809-
The call is prefixed with the keyword `do` and, instead of writing the
1810-
final procedure inside the argument list, it appears outside of the
1811-
parentheses, where it looks more like a typical block of
1812-
code.
1813-
1814-
`do` is a convenient way to create tasks with the `task::spawn`
1815-
function. `spawn` has the signature `spawn(fn: proc())`. In other
1816-
words, it is a function that takes an owned closure that takes no
1817-
arguments.
1818-
1819-
~~~~
1820-
use std::task::spawn;
1821-
1822-
do spawn() || {
1823-
debug!("I'm a task, whatever");
1824-
}
1825-
~~~~
1826-
1827-
Look at all those bars and parentheses -- that's two empty argument
1828-
lists back to back. Since that is so unsightly, empty argument lists
1829-
may be omitted from `do` expressions.
1799+
A practical example of this pattern is found when using the `spawn` function,
1800+
which starts a new task.
18301801
18311802
~~~~
18321803
use std::task::spawn;
1833-
1834-
do spawn {
1835-
debug!("Kablam!");
1836-
}
1804+
spawn(proc() {
1805+
debug!("I'm a new task")
1806+
});
18371807
~~~~
18381808
1839-
If you want to see the output of `debug!` statements, you will need to turn on `debug!` logging.
1840-
To enable `debug!` logging, set the RUST_LOG environment variable to the name of your crate, which, for a file named `foo.rs`, will be `foo` (e.g., with bash, `export RUST_LOG=foo`).
1809+
If you want to see the output of `debug!` statements, you will need to turn on
1810+
`debug!` logging. To enable `debug!` logging, set the RUST_LOG environment
1811+
variable to the name of your crate, which, for a file named `foo.rs`, will be
1812+
`foo` (e.g., with bash, `export RUST_LOG=foo`).
18411813
18421814
# Methods
18431815

src/compiletest/runtest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
317317
loop {
318318
//waiting 1 second for gdbserver start
319319
timer::sleep(1000);
320-
let result = do task::try {
320+
let result = task::try(proc() {
321321
tcp::TcpStream::connect(
322322
SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 5039 });
323-
};
323+
});
324324
if result.is_err() {
325325
continue;
326326
}

0 commit comments

Comments
 (0)