Skip to content

Commit b3d86c8

Browse files
committed
---
yaml --- r: 34785 b: refs/heads/master c: f2544d8 h: refs/heads/master i: 34783: 00055ae v: v3
1 parent 53d98a4 commit b3d86c8

File tree

280 files changed

+4217
-3658
lines changed

Some content is hidden

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

280 files changed

+4217
-3658
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 32baf1c54c4214f5a50da53979008ef9bcdad359
2+
refs/heads/master: f2544d8d80f20e9c1e39c3c455b18ebe1922d1d5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024

trunk/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

trunk/doc/tutorial.md

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,9 +1502,9 @@ and [`core::str`]. Here are some examples.
15021502
# fn unwrap_crayon(c: Crayon) -> int { 0 }
15031503
# fn eat_crayon_wax(i: int) { }
15041504
# fn store_crayon_in_nasal_cavity(i: uint, c: Crayon) { }
1505-
# fn crayon_to_str(c: Crayon) -> ~str { ~"" }
1505+
# fn crayon_to_str(c: Crayon) -> &str { "" }
15061506
1507-
let crayons = &[Almond, AntiqueBrass, Apricot];
1507+
let crayons = [Almond, AntiqueBrass, Apricot];
15081508
15091509
// Check the length of the vector
15101510
assert crayons.len() == 3;
@@ -1569,7 +1569,7 @@ let bloop = |well, oh: mygoodness| -> what_the { fail oh(well) };
15691569
~~~~
15701570

15711571
There are several forms of closure, each with its own role. The most
1572-
common, called a _stack closure_, has type `fn&` and can directly
1572+
common, called a _stack closure_, has type `&fn` and can directly
15731573
access local variables in the enclosing scope.
15741574

15751575
~~~~
@@ -1591,7 +1591,7 @@ pervasively in Rust code.
15911591
When you need to store a closure in a data structure, a stack closure
15921592
will not do, since the compiler will refuse to let you store it. For
15931593
this purpose, Rust provides a type of closure that has an arbitrary
1594-
lifetime, written `fn@` (boxed closure, analogous to the `@` pointer
1594+
lifetime, written `@fn` (boxed closure, analogous to the `@` pointer
15951595
type described earlier). This type of closure *is* first-class.
15961596

15971597
A managed closure does not directly access its environment, but merely
@@ -1604,8 +1604,9 @@ returns it from a function, and then calls it:
16041604

16051605
~~~~
16061606
# extern mod std;
1607-
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
1608-
return fn@(s: ~str) -> ~str { s + suffix };
1607+
fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
1608+
// The compiler knows that we intend this closure to be of type @fn
1609+
return |s| s + suffix;
16091610
}
16101611
16111612
fn main() {
@@ -1614,22 +1615,9 @@ fn main() {
16141615
}
16151616
~~~~
16161617

1617-
This example uses the long closure syntax, `fn@(s: ~str) ...`. Using
1618-
this syntax makes it explicit that we are declaring a boxed
1619-
closure. In practice, boxed closures are usually defined with the
1620-
short closure syntax introduced earlier, in which case the compiler
1621-
infers the type of closure. Thus our managed closure example could
1622-
also be written:
1623-
1624-
~~~~
1625-
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
1626-
return |s| s + suffix;
1627-
}
1628-
~~~~
1629-
16301618
## Owned closures
16311619

1632-
Owned closures, written `fn~` in analogy to the `~` pointer type,
1620+
Owned closures, written `~fn` in analogy to the `~` pointer type,
16331621
hold on to things that can safely be sent between
16341622
processes. They copy the values they close over, much like managed
16351623
closures, but they also own them: that is, no other code can access
@@ -1649,12 +1637,10 @@ callers may pass any kind of closure.
16491637

16501638
~~~~
16511639
fn call_twice(f: fn()) { f(); f(); }
1652-
call_twice(|| { ~"I am an inferred stack closure"; } );
1653-
call_twice(fn&() { ~"I am also a stack closure"; } );
1654-
call_twice(fn@() { ~"I am a managed closure"; });
1655-
call_twice(fn~() { ~"I am an owned closure"; });
1656-
fn bare_function() { ~"I am a plain function"; }
1657-
call_twice(bare_function);
1640+
let closure = || { "I'm a closure, and it doesn't matter what type I am"; };
1641+
fn function() { "I'm a normal function"; }
1642+
call_twice(closure);
1643+
call_twice(function);
16581644
~~~~
16591645

16601646
> ***Note:*** Both the syntax and the semantics will be changing
@@ -1693,7 +1679,7 @@ structure.
16931679
~~~~
16941680
# fn each(v: &[int], op: fn(v: &int)) { }
16951681
# fn do_some_work(i: &int) { }
1696-
each(&[1, 2, 3], |n| {
1682+
each([1, 2, 3], |n| {
16971683
do_some_work(n);
16981684
});
16991685
~~~~
@@ -1704,7 +1690,7 @@ call that can be written more like a built-in control structure:
17041690
~~~~
17051691
# fn each(v: &[int], op: fn(v: &int)) { }
17061692
# fn do_some_work(i: &int) { }
1707-
do each(&[1, 2, 3]) |n| {
1693+
do each([1, 2, 3]) |n| {
17081694
do_some_work(n);
17091695
}
17101696
~~~~
@@ -1715,7 +1701,7 @@ parentheses, where it looks more like a typical block of
17151701
code.
17161702

17171703
`do` is a convenient way to create tasks with the `task::spawn`
1718-
function. `spawn` has the signature `spawn(fn: fn~())`. In other
1704+
function. `spawn` has the signature `spawn(fn: ~fn())`. In other
17191705
words, it is a function that takes an owned closure that takes no
17201706
arguments.
17211707

@@ -1765,9 +1751,9 @@ And using this function to iterate over a vector:
17651751
~~~~
17661752
# use each = vec::each;
17671753
# use println = io::println;
1768-
each(&[2, 4, 8, 5, 16], |n| {
1754+
each([2, 4, 8, 5, 16], |n| {
17691755
if *n % 2 != 0 {
1770-
println(~"found odd number!");
1756+
println("found odd number!");
17711757
false
17721758
} else { true }
17731759
});
@@ -1782,9 +1768,9 @@ to the next iteration, write `loop`.
17821768
~~~~
17831769
# use each = vec::each;
17841770
# use println = io::println;
1785-
for each(&[2, 4, 8, 5, 16]) |n| {
1771+
for each([2, 4, 8, 5, 16]) |n| {
17861772
if *n % 2 != 0 {
1787-
println(~"found odd number!");
1773+
println("found odd number!");
17881774
break;
17891775
}
17901776
}
@@ -1827,7 +1813,7 @@ fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
18271813
for vec::each(vector) |element| {
18281814
accumulator.push(function(element));
18291815
}
1830-
return accumulator;
1816+
return (move accumulator);
18311817
}
18321818
~~~~
18331819

@@ -1967,12 +1953,12 @@ impl int: Printable {
19671953
fn print() { io::println(fmt!("%d", self)) }
19681954
}
19691955
1970-
impl ~str: Printable {
1956+
impl &str: Printable {
19711957
fn print() { io::println(self) }
19721958
}
19731959
19741960
# 1.print();
1975-
# (~"foo").print();
1961+
# ("foo").print();
19761962
~~~~
19771963

19781964
Methods defined in an implementation of a trait may be called just like
@@ -2120,7 +2106,7 @@ impl @Rectangle: Drawable { fn draw() { ... } }
21202106
21212107
let c: @Circle = @new_circle();
21222108
let r: @Rectangle = @new_rectangle();
2123-
draw_all(&[c as @Drawable, r as @Drawable]);
2109+
draw_all([c as @Drawable, r as @Drawable]);
21242110
~~~~
21252111

21262112
We omit the code for `new_circle` and `new_rectangle`; imagine that
@@ -2162,8 +2148,8 @@ additional modules.
21622148

21632149
~~~~
21642150
mod farm {
2165-
pub fn chicken() -> ~str { ~"cluck cluck" }
2166-
pub fn cow() -> ~str { ~"mooo" }
2151+
pub fn chicken() -> &str { "cluck cluck" }
2152+
pub fn cow() -> &str { "mooo" }
21672153
}
21682154
21692155
fn main() {
@@ -2360,13 +2346,13 @@ these two files:
23602346
~~~~
23612347
// world.rs
23622348
#[link(name = "world", vers = "1.0")];
2363-
fn explore() -> ~str { ~"world" }
2349+
pub fn explore() -> &str { "world" }
23642350
~~~~
23652351

23662352
~~~~ {.xfail-test}
23672353
// main.rs
23682354
extern mod world;
2369-
fn main() { io::println(~"hello " + world::explore()); }
2355+
fn main() { io::println("hello " + world::explore()); }
23702356
~~~~
23712357

23722358
Now compile and run like this (adjust to your platform if necessary):

trunk/src/cargo/cargo.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ fn configure(opts: Options) -> Cargo {
705705
~" or package manager to get it to work correctly");
706706
}
707707

708-
c
708+
move c
709709
}
710710

711711
fn for_each_package(c: &Cargo, b: fn(s: @Source, p: &Package)) {
@@ -1162,20 +1162,20 @@ fn sync_one_file(c: &Cargo, dir: &Path, src: @Source) -> bool {
11621162
}
11631163
match (src.key, src.keyfp) {
11641164
(Some(_), Some(f)) => {
1165-
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
1165+
let r = pgp::verify(&c.root, &pkgfile, &sigfile);
11661166

11671167
if !r {
1168-
error(fmt!("signature verification failed for source %s",
1169-
name));
1168+
error(fmt!("signature verification failed for source %s with \
1169+
key %s", name, f));
11701170
return false;
11711171
}
11721172

11731173
if has_src_file {
1174-
let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
1174+
let e = pgp::verify(&c.root, &srcfile, &srcsigfile);
11751175

11761176
if !e {
1177-
error(fmt!("signature verification failed for source %s",
1178-
name));
1177+
error(fmt!("signature verification failed for source %s \
1178+
with key %s", name, f));
11791179
return false;
11801180
}
11811181
}
@@ -1273,21 +1273,21 @@ fn sync_one_git(c: &Cargo, dir: &Path, src: @Source) -> bool {
12731273
}
12741274
match (src.key, src.keyfp) {
12751275
(Some(_), Some(f)) => {
1276-
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
1276+
let r = pgp::verify(&c.root, &pkgfile, &sigfile);
12771277

12781278
if !r {
1279-
error(fmt!("signature verification failed for source %s",
1280-
name));
1279+
error(fmt!("signature verification failed for source %s with \
1280+
key %s", name, f));
12811281
rollback(name, dir, false);
12821282
return false;
12831283
}
12841284

12851285
if has_src_file {
1286-
let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
1286+
let e = pgp::verify(&c.root, &srcfile, &srcsigfile);
12871287

12881288
if !e {
1289-
error(fmt!("signature verification failed for source %s",
1290-
name));
1289+
error(fmt!("signature verification failed for source %s \
1290+
with key %s", name, f));
12911291
rollback(name, dir, false);
12921292
return false;
12931293
}
@@ -1370,11 +1370,11 @@ fn sync_one_curl(c: &Cargo, dir: &Path, src: @Source) -> bool {
13701370
return false;
13711371
}
13721372

1373-
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
1373+
let r = pgp::verify(&c.root, &pkgfile, &sigfile);
13741374

13751375
if !r {
1376-
error(fmt!("signature verification failed for source %s",
1377-
name));
1376+
error(fmt!("signature verification failed for source %s with \
1377+
key %s", name, f));
13781378
return false;
13791379
}
13801380

@@ -1390,11 +1390,11 @@ fn sync_one_curl(c: &Cargo, dir: &Path, src: @Source) -> bool {
13901390
return false;
13911391
}
13921392

1393-
let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
1393+
let e = pgp::verify(&c.root, &srcfile, &srcsigfile);
13941394

13951395
if !e {
13961396
error(~"signature verification failed for " +
1397-
~"source " + name);
1397+
~"source " + name + ~" with key " + f);
13981398
return false;
13991399
}
14001400
}
@@ -1463,8 +1463,7 @@ fn cmd_init(c: &Cargo) {
14631463
return;
14641464
}
14651465

1466-
let r = pgp::verify(&c.root, &srcfile, &sigfile,
1467-
pgp::signing_key_fp());
1466+
let r = pgp::verify(&c.root, &srcfile, &sigfile);
14681467
if !r {
14691468
error(fmt!("signature verification failed for '%s'",
14701469
srcfile.to_str()));
@@ -1615,10 +1614,10 @@ fn dump_sources(c: &Cargo) {
16151614
_ => ()
16161615
}
16171616

1618-
hash.insert(copy k, json::Object(chash));
1617+
hash.insert(copy k, json::Object(move chash));
16191618
}
16201619

1621-
json::to_writer(writer, &json::Object(hash))
1620+
json::to_writer(writer, &json::Object(move hash))
16221621
}
16231622
result::Err(e) => {
16241623
error(fmt!("could not dump sources: %s", e));

0 commit comments

Comments
 (0)