Skip to content

Commit 5655ae4

Browse files
committed
auto merge of #5197 : pcwalton/rust/fn-types, r=pcwalton
r? @catamorphism
2 parents 826644e + ccec510 commit 5655ae4

File tree

270 files changed

+1098
-1331
lines changed

Some content is hidden

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

270 files changed

+1098
-1331
lines changed

doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ Functions within foreign modules are declared in the same way as other Rust func
13601360
with the exception that they may not have a body and are instead terminated by a semicolon.
13611361

13621362
~~~
1363-
# use libc::{c_char, FILE};
1363+
# use core::libc::{c_char, FILE};
13641364
# #[nolink]
13651365
13661366
extern mod c {

doc/tutorial-ffi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ should compile and run without any extra effort.
1414

1515
~~~~ {.xfail-test}
1616
extern mod std;
17-
use libc::c_uint;
17+
use core::libc::c_uint;
1818
1919
extern mod crypto {
2020
fn SHA1(src: *u8, sz: c_uint, out: *u8) -> *u8;
@@ -217,7 +217,7 @@ microsecond-resolution timer.
217217

218218
~~~~
219219
extern mod std;
220-
use libc::c_ulonglong;
220+
use core::libc::c_ulonglong;
221221
222222
struct timeval {
223223
tv_sec: c_ulonglong,

doc/tutorial-tasks.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ calling the `spawn` function with a closure argument. `spawn` executes the
8080
closure in the new task.
8181

8282
~~~~
83-
# use io::println;
84-
use task::spawn;
83+
# use core::io::println;
84+
use core::task::spawn;
8585
8686
// Print something profound in a different task using a named function
8787
fn print_message() { println("I am running in a different task!"); }
@@ -110,8 +110,8 @@ execution. Like any closure, the function passed to `spawn` may capture
110110
an environment that it carries across tasks.
111111

112112
~~~
113-
# use io::println;
114-
# use task::spawn;
113+
# use core::io::println;
114+
# use core::task::spawn;
115115
# fn generate_task_number() -> int { 0 }
116116
// Generate some state locally
117117
let child_task_number = generate_task_number();
@@ -127,8 +127,8 @@ in parallel. Thus, on a multicore machine, running the following code
127127
should interleave the output in vaguely random order.
128128

129129
~~~
130-
# use io::print;
131-
# use task::spawn;
130+
# use core::io::print;
131+
# use core::task::spawn;
132132
133133
for int::range(0, 20) |child_task_number| {
134134
do spawn {
@@ -156,8 +156,8 @@ endpoint. Consider the following example of calculating two results
156156
concurrently:
157157

158158
~~~~
159-
use task::spawn;
160-
use comm::{stream, Port, Chan};
159+
use core::task::spawn;
160+
use core::comm::{stream, Port, Chan};
161161
162162
let (port, chan): (Port<int>, Chan<int>) = stream();
163163
@@ -178,7 +178,7 @@ stream for sending and receiving integers (the left-hand side of the `let`,
178178
a tuple into its component parts).
179179

180180
~~~~
181-
# use comm::{stream, Chan, Port};
181+
# use core::comm::{stream, Chan, Port};
182182
let (port, chan): (Port<int>, Chan<int>) = stream();
183183
~~~~
184184

@@ -187,9 +187,8 @@ which will wait to receive the data on the port. The next statement
187187
spawns the child task.
188188

189189
~~~~
190-
# use task::{spawn};
191-
# use task::spawn;
192-
# use comm::{stream, Port, Chan};
190+
# use core::task::spawn;
191+
# use core::comm::{stream, Port, Chan};
193192
# fn some_expensive_computation() -> int { 42 }
194193
# let (port, chan) = stream();
195194
do spawn || {
@@ -209,7 +208,7 @@ computation, then waits for the child's result to arrive on the
209208
port:
210209

211210
~~~~
212-
# use comm::{stream, Port, Chan};
211+
# use core::comm::{stream, Port, Chan};
213212
# fn some_other_expensive_computation() {}
214213
# let (port, chan) = stream::<int>();
215214
# chan.send(0);
@@ -224,8 +223,8 @@ example needed to compute multiple results across a number of tasks? The
224223
following program is ill-typed:
225224

226225
~~~ {.xfail-test}
227-
# use task::{spawn};
228-
# use comm::{stream, Port, Chan};
226+
# use core::task::{spawn};
227+
# use core::comm::{stream, Port, Chan};
229228
# fn some_expensive_computation() -> int { 42 }
230229
let (port, chan) = stream();
231230
@@ -244,8 +243,8 @@ Instead we can use a `SharedChan`, a type that allows a single
244243
`Chan` to be shared by multiple senders.
245244

246245
~~~
247-
# use task::spawn;
248-
use comm::{stream, SharedChan};
246+
# use core::task::spawn;
247+
use core::comm::{stream, SharedChan};
249248
250249
let (port, chan) = stream();
251250
let chan = SharedChan(chan);
@@ -277,8 +276,8 @@ illustrate the point. For reference, written with multiple streams, it
277276
might look like the example below.
278277

279278
~~~
280-
# use task::spawn;
281-
# use comm::{stream, Port, Chan};
279+
# use core::task::spawn;
280+
# use core::comm::{stream, Port, Chan};
282281
283282
// Create a vector of ports, one for each child task
284283
let ports = do vec::from_fn(3) |init_val| {
@@ -309,7 +308,7 @@ All tasks are, by default, _linked_ to each other. That means that the fates
309308
of all tasks are intertwined: if one fails, so do all the others.
310309

311310
~~~
312-
# use task::spawn;
311+
# use core::task::spawn;
313312
# fn do_some_work() { loop { task::yield() } }
314313
# do task::try {
315314
// Create a child task that fails
@@ -393,8 +392,8 @@ internally, with additional logic to wait for the child task to finish
393392
before returning. Hence:
394393

395394
~~~
396-
# use comm::{stream, Chan, Port};
397-
# use task::{spawn, try};
395+
# use core::comm::{stream, Chan, Port};
396+
# use core::task::{spawn, try};
398397
# fn sleep_forever() { loop { task::yield() } }
399398
# do task::try {
400399
let (receiver, sender): (Port<int>, Chan<int>) = stream();
@@ -489,8 +488,8 @@ response itself is simply the stringified version of the received value,
489488
Here is the code for the parent task:
490489

491490
~~~~
491+
# use core::task::spawn;
492492
# use std::comm::DuplexStream;
493-
# use task::spawn;
494493
# fn stringifier(channel: &DuplexStream<~str, uint>) {
495494
# let mut value: uint;
496495
# loop {

doc/tutorial.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ and [`core::str`]. Here are some examples.
13131313
[`core::str`]: core/str.html
13141314

13151315
~~~
1316-
# use io::println;
1316+
# use core::io::println;
13171317
# enum Crayon {
13181318
# Almond, AntiqueBrass, Apricot,
13191319
# Aquamarine, Asparagus, AtomicTangerine,
@@ -1368,7 +1368,7 @@ Rust also supports _closures_, functions that can access variables in
13681368
the enclosing scope.
13691369

13701370
~~~~
1371-
# use println = io::println;
1371+
# use println = core::io::println;
13721372
fn call_closure_with_ten(b: fn(int)) { b(10); }
13731373
13741374
let captured_var = 20;
@@ -1525,7 +1525,7 @@ words, it is a function that takes an owned closure that takes no
15251525
arguments.
15261526

15271527
~~~~
1528-
use task::spawn;
1528+
use core::task::spawn;
15291529
15301530
do spawn() || {
15311531
debug!("I'm a task, whatever");
@@ -1537,7 +1537,7 @@ lists back to back. Since that is so unsightly, empty argument lists
15371537
may be omitted from `do` expressions.
15381538

15391539
~~~~
1540-
# use task::spawn;
1540+
# use core::task::spawn;
15411541
do spawn {
15421542
debug!("Kablam!");
15431543
}
@@ -1568,8 +1568,8 @@ fn each(v: &[int], op: fn(v: &int) -> bool) {
15681568
And using this function to iterate over a vector:
15691569

15701570
~~~~
1571-
# use each = vec::each;
1572-
# use println = io::println;
1571+
# use each = core::vec::each;
1572+
# use println = core::io::println;
15731573
each([2, 4, 8, 5, 16], |n| {
15741574
if *n % 2 != 0 {
15751575
println("found odd number!");
@@ -1585,8 +1585,8 @@ out of the loop, you just write `break`. To skip ahead
15851585
to the next iteration, write `loop`.
15861586

15871587
~~~~
1588-
# use each = vec::each;
1589-
# use println = io::println;
1588+
# use each = core::vec::each;
1589+
# use println = core::io::println;
15901590
for each([2, 4, 8, 5, 16]) |n| {
15911591
if *n % 2 != 0 {
15921592
println("found odd number!");
@@ -1601,7 +1601,7 @@ normally allowed in closures, in a block that appears as the body of a
16011601
the enclosing function, not just the loop body.
16021602

16031603
~~~~
1604-
# use each = vec::each;
1604+
# use each = core::vec::each;
16051605
fn contains(v: &[int], elt: int) -> bool {
16061606
for each(v) |x| {
16071607
if (*x == elt) { return true; }
@@ -1616,7 +1616,7 @@ In these situations it can be convenient to lean on Rust's
16161616
argument patterns to bind `x` to the actual value, not the pointer.
16171617

16181618
~~~~
1619-
# use each = vec::each;
1619+
# use each = core::vec::each;
16201620
# fn contains(v: &[int], elt: int) -> bool {
16211621
for each(v) |&x| {
16221622
if (x == elt) { return true; }
@@ -1758,8 +1758,8 @@ Constructors are one common application for static methods, as in `new` above.
17581758
To call a static method, you have to prefix it with the type name and a double colon:
17591759

17601760
~~~~
1761-
# use float::consts::pi;
1762-
# use float::sqrt;
1761+
# use core::float::consts::pi;
1762+
# use core::float::sqrt;
17631763
struct Circle { radius: float }
17641764
impl Circle {
17651765
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
@@ -2030,8 +2030,8 @@ The compiler will use type inference to decide which implementation to call.
20302030

20312031
~~~~
20322032
trait Shape { static fn new(area: float) -> Self; }
2033-
# use float::consts::pi;
2034-
# use float::sqrt;
2033+
# use core::float::consts::pi;
2034+
# use core::float::sqrt;
20352035
struct Circle { radius: float }
20362036
struct Square { length: float }
20372037
@@ -2189,8 +2189,8 @@ Now, we can implement `Circle` on a type only if we also implement `Shape`.
21892189
# trait Shape { fn area(&self) -> float; }
21902190
# trait Circle : Shape { fn radius(&self) -> float; }
21912191
# struct Point { x: float, y: float }
2192-
# use float::consts::pi;
2193-
# use float::sqrt;
2192+
# use core::float::consts::pi;
2193+
# use core::float::sqrt;
21942194
# fn square(x: float) -> float { x * x }
21952195
struct CircleStruct { center: Point, radius: float }
21962196
impl Circle for CircleStruct {
@@ -2224,8 +2224,8 @@ Likewise, supertrait methods may also be called on trait objects.
22242224
~~~ {.xfail-test}
22252225
# trait Shape { fn area(&self) -> float; }
22262226
# trait Circle : Shape { fn radius(&self) -> float; }
2227-
# use float::consts::pi;
2228-
# use float::sqrt;
2227+
# use core::float::consts::pi;
2228+
# use core::float::sqrt;
22292229
# struct Point { x: float, y: float }
22302230
# struct CircleStruct { center: Point, radius: float }
22312231
# impl Circle for CircleStruct { fn radius(&self) -> float { sqrt(self.area() / pi) } }
@@ -2291,13 +2291,12 @@ be private. But this encapsulation is at the module level, not the
22912291
struct level. Note that fields and methods are _public_ by default.
22922292

22932293
~~~
2294-
mod farm {
2295-
# use farm;
2294+
pub mod farm {
22962295
# pub type Chicken = int;
22972296
# type Cow = int;
22982297
# enum Human = int;
22992298
# impl Human { fn rest(&self) { } }
2300-
# pub fn make_me_a_farm() -> farm::Farm { farm::Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
2299+
# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
23012300
pub struct Farm {
23022301
priv chickens: ~[Chicken],
23032302
priv cows: ~[Cow],

src/compiletest/compiletest.rc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ extern mod std(vers = "0.6");
2222

2323
use core::*;
2424

25-
mod procsrv;
26-
mod util;
27-
mod header;
28-
mod runtest;
29-
mod common;
30-
mod errors;
25+
pub mod procsrv;
26+
pub mod util;
27+
pub mod header;
28+
pub mod runtest;
29+
pub mod common;
30+
pub mod errors;
3131

3232
use std::getopts;
3333
use std::test;
3434

3535
use core::{result, either};
36-
use result::{Ok, Err};
36+
use core::result::{Ok, Err};
3737

3838
use common::config;
3939
use common::mode_run_pass;
@@ -223,7 +223,7 @@ pub fn make_test_name(config: config, testfile: &Path) -> test::TestName {
223223

224224
pub fn make_test_closure(config: config, testfile: &Path) -> test::TestFn {
225225
let testfile = testfile.to_str();
226-
test::DynTestFn(fn~() { runtest::run(config, testfile) })
226+
test::DynTestFn(|| runtest::run(config, testfile))
227227
}
228228

229229
// Local Variables:

src/compiletest/errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
use core::prelude::*;
1212

1313
use common::config;
14-
use io;
15-
use io::ReaderUtil;
16-
use str;
14+
15+
use core::io;
16+
use core::io::ReaderUtil;
17+
use core::str;
1718

1819
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
1920

src/compiletest/header.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use core::prelude::*;
1212

1313
use common;
1414
use common::config;
15-
use io;
16-
use io::ReaderUtil;
17-
use os;
18-
use str;
15+
16+
use core::io::ReaderUtil;
17+
use core::io;
18+
use core::os;
19+
use core::str;
1920

2021
pub struct TestProps {
2122
// Lines that should be expected, in order, on standard out

src/compiletest/procsrv.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
use core::prelude::*;
1212

13-
use io;
14-
use io::{ReaderUtil, WriterUtil};
15-
use libc;
16-
use libc::{c_int, pid_t};
17-
use os;
18-
use run;
19-
use run::spawn_process;
20-
use pipes;
21-
use str;
22-
use task;
23-
use vec;
13+
use core::io::{ReaderUtil, WriterUtil};
14+
use core::io;
15+
use core::libc::{c_int, pid_t};
16+
use core::libc;
17+
use core::os;
18+
use core::pipes;
19+
use core::run::spawn_process;
20+
use core::run;
21+
use core::str;
22+
use core::task;
23+
use core::vec;
2424

2525
#[cfg(target_os = "win32")]
2626
fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {

0 commit comments

Comments
 (0)