rollup merge of #20157: alexcrichton/issue-20068

This commit is contained in:
Alex Crichton 2015-01-02 08:54:58 -08:00
commit 5696ea5894
315 changed files with 1701 additions and 1235 deletions

View File

@ -22,8 +22,8 @@ extern crate regex;
use std::os; use std::os;
use std::io; use std::io;
use std::io::fs; use std::io::fs;
use std::str::FromStr; use std::str::{FromStr, from_str};
use std::thunk::{Thunk}; use std::thunk::Thunk;
use getopts::{optopt, optflag, reqopt}; use getopts::{optopt, optflag, reqopt};
use common::Config; use common::Config;
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen}; use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};

View File

@ -450,6 +450,8 @@ them.
~~~no_run ~~~no_run
extern crate libc; extern crate libc;
use std::c_str::ToCStr;
use std::ptr; use std::ptr;
#[link(name = "readline")] #[link(name = "readline")]

View File

@ -26,7 +26,7 @@ in the `$`s, they just indicate the start of each command):
curl -L https://static.rust-lang.org/rustup.sh | sudo sh curl -L https://static.rust-lang.org/rustup.sh | sudo sh
``` ```
If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`, If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`,
please keep reading and see our disclaimer below. And feel free to use a two-step version of the installation and examine our installation script: please keep reading and see our disclaimer below. And feel free to use a two-step version of the installation and examine our installation script:
```bash ```bash
@ -1106,13 +1106,21 @@ enum Ordering {
``` ```
An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given
time. Here's an example: time.
Because `Ordering` is provided by the standard library, we can use the `use`
keyword to use it in our code. We'll learn more about `use` later, but it's
used to bring names into scope.
Here's an example of how to use `Ordering`:
```{rust} ```{rust}
use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering { fn cmp(a: int, b: int) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
fn main() { fn main() {
@ -1121,28 +1129,35 @@ fn main() {
let ordering = cmp(x, y); // ordering: Ordering let ordering = cmp(x, y); // ordering: Ordering
if ordering == Less { if ordering == Ordering::Less {
println!("less"); println!("less");
} else if ordering == Greater { } else if ordering == Ordering::Greater {
println!("greater"); println!("greater");
} else if ordering == Equal { } else if ordering == Ordering::Equal {
println!("equal"); println!("equal");
} }
} }
``` ```
`cmp` is a function that compares two things, and returns an `Ordering`. We There's a symbol here we haven't seen before: the double colon (`::`).
return either `Less`, `Greater`, or `Equal`, depending on if the two values This is used to indicate a namesapce. In this case, `Ordering` lives in
are greater, less, or equal. the `cmp` submodule of the `std` module. We'll talk more about modules
later in the guide. For now, all you need to know is that you can `use`
things from the standard library if you need them.
Okay, let's talk about the actual code in the example. `cmp` is a function that
compares two things, and returns an `Ordering`. We return either
`Ordering::Less`, `Ordering::Greater`, or `Ordering::Equal`, depending on if
the two values are greater, less, or equal. Note that each variant of the
`enum` is namespaced under the `enum` itself: it's `Ordering::Greater` not
`Greater`.
The `ordering` variable has the type `Ordering`, and so contains one of the The `ordering` variable has the type `Ordering`, and so contains one of the
three values. We can then do a bunch of `if`/`else` comparisons to check three values. We can then do a bunch of `if`/`else` comparisons to check which
which one it is. one it is. However, repeated `if`/`else` comparisons get quite tedious. Rust
has a feature that not only makes them nicer to read, but also makes sure that
However, repeated `if`/`else` comparisons get quite tedious. Rust has a feature you never miss a case. Before we get to that, though, let's talk about another
that not only makes them nicer to read, but also makes sure that you never kind of enum: one with values.
miss a case. Before we get to that, though, let's talk about another kind of
enum: one with values.
This enum has two variants, one of which has a value: This enum has two variants, one of which has a value:
@ -1175,18 +1190,19 @@ enum StringResult {
ErrorReason(String), ErrorReason(String),
} }
``` ```
Where a `StringResult` is either a `StringOK`, with the result of a computation, or an Where a `StringResult` is either a `StringResult::StringOK`, with the result of
`ErrorReason` with a `String` explaining what caused the computation to fail. These kinds of a computation, or an `StringResult::ErrorReason` with a `String` explaining
`enum`s are actually very useful and are even part of the standard library. what caused the computation to fail. These kinds of `enum`s are actually very
useful and are even part of the standard library.
Enum variants are namespaced under the enum names. For example, here is an example of using Here is an example of using our `StringResult`:
our `StringResult`:
```rust ```rust
# enum StringResult { enum StringResult {
# StringOK(String), StringOK(String),
# ErrorReason(String), ErrorReason(String),
# } }
fn respond(greeting: &str) -> StringResult { fn respond(greeting: &str) -> StringResult {
if greeting == "Hello" { if greeting == "Hello" {
StringResult::StringOK("Good morning!".to_string()) StringResult::StringOK("Good morning!".to_string())
@ -1196,10 +1212,7 @@ fn respond(greeting: &str) -> StringResult {
} }
``` ```
Notice that we need both the enum name and the variant name: `StringResult::StringOK`, but That's a lot of typing! We can use the `use` keyword to make it shorter:
we didn't need to with `Ordering` we just said `Greater` rather than `Ordering::Greater`.
There's a reason: the Rust prelude imports the variants of `Ordering` as well as the enum
itself. We can use the `use` keyword to do something similar with `StringResult`:
```rust ```rust
use StringResult::StringOK; use StringResult::StringOK;
@ -1221,12 +1234,11 @@ fn respond(greeting: &str) -> StringResult {
} }
``` ```
We'll learn more about `use` later, but it's used to bring names into scope. `use` declarations `use` declarations must come before anything else, which looks a little strange in this example,
must come before anything else, which looks a little strange in this example, since we `use` since we `use` the variants before we define them. Anyway, in the body of `respond`, we can just
the variants before we define them. Anyway, in the body of `respond`, we can just say `StringOK` say `StringOK` now, rather than the full `StringResult::StringOK`. Importing variants can be
now, rather than the full `StringResult::StringOK`. Importing variants can be convenient, but can convenient, but can also cause name conflicts, so do this with caution. It's considered good style
also cause name conflicts, so do this with caution. It's considered good style to rarely import to rarely import variants for this reason.
variants for this reason.
As you can see, `enum`s with values are quite a powerful tool for data representation, As you can see, `enum`s with values are quite a powerful tool for data representation,
and can be even more useful when they're generic across types. Before we get to generics, and can be even more useful when they're generic across types. Before we get to generics,
@ -1280,10 +1292,12 @@ for every possible value of `x`, and so our program will compile successfully.
section on enums? section on enums?
```{rust} ```{rust}
use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering { fn cmp(a: int, b: int) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
fn main() { fn main() {
@ -1292,11 +1306,11 @@ fn main() {
let ordering = cmp(x, y); let ordering = cmp(x, y);
if ordering == Less { if ordering == Ordering::Less {
println!("less"); println!("less");
} else if ordering == Greater { } else if ordering == Ordering::Greater {
println!("greater"); println!("greater");
} else if ordering == Equal { } else if ordering == Ordering::Equal {
println!("equal"); println!("equal");
} }
} }
@ -1305,10 +1319,12 @@ fn main() {
We can re-write this as a `match`: We can re-write this as a `match`:
```{rust} ```{rust}
use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering { fn cmp(a: int, b: int) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
fn main() { fn main() {
@ -1316,9 +1332,9 @@ fn main() {
let y = 10i; let y = 10i;
match cmp(x, y) { match cmp(x, y) {
Less => println!("less"), Ordering::Less => println!("less"),
Greater => println!("greater"), Ordering::Greater => println!("greater"),
Equal => println!("equal"), Ordering::Equal => println!("equal"),
} }
} }
``` ```
@ -1365,10 +1381,12 @@ side of a `let` binding or directly where an expression is used. We could
also implement the previous line like this: also implement the previous line like this:
```{rust} ```{rust}
use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering { fn cmp(a: int, b: int) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
fn main() { fn main() {
@ -1376,9 +1394,9 @@ fn main() {
let y = 10i; let y = 10i;
println!("{}", match cmp(x, y) { println!("{}", match cmp(x, y) {
Less => "less", Ordering::Less => "less",
Greater => "greater", Ordering::Greater => "greater",
Equal => "equal", Ordering::Equal => "equal",
}); });
} }
``` ```
@ -2139,6 +2157,7 @@ guess to the secret number:
```{rust,ignore} ```{rust,ignore}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2157,16 +2176,16 @@ fn main() {
println!("You guessed: {}", input); println!("You guessed: {}", input);
match cmp(input, secret_number) { match cmp(input, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => println!("You win!"), Ordering::Equal => println!("You win!"),
} }
} }
fn cmp(a: int, b: int) -> Ordering { fn cmp(a: int, b: int) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2193,6 +2212,7 @@ we wrote the `cmp` function! Let's change it to take `uint`s:
```{rust,ignore} ```{rust,ignore}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2211,16 +2231,16 @@ fn main() {
println!("You guessed: {}", input); println!("You guessed: {}", input);
match cmp(input, secret_number) { match cmp(input, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => println!("You win!"), Ordering::Equal => println!("You win!"),
} }
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2290,6 +2310,7 @@ Anyway, with us now converting our input to a number, our code looks like this:
```{rust,ignore} ```{rust,ignore}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2308,16 +2329,16 @@ fn main() {
println!("You guessed: {}", input_num); println!("You guessed: {}", input_num);
match cmp(input_num, secret_number) { match cmp(input_num, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => println!("You win!"), Ordering::Equal => println!("You win!"),
} }
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2339,6 +2360,7 @@ to do that. Try this code:
```{rust,no_run} ```{rust,no_run}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2366,16 +2388,16 @@ fn main() {
println!("You guessed: {}", num); println!("You guessed: {}", num);
match cmp(num, secret_number) { match cmp(num, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => println!("You win!"), Ordering::Equal => println!("You win!"),
} }
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2405,6 +2427,7 @@ code looks like this:
```{rust,no_run} ```{rust,no_run}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2432,16 +2455,16 @@ fn main() {
println!("You guessed: {}", num); println!("You guessed: {}", num);
match cmp(num, secret_number) { match cmp(num, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => println!("You win!"), Ordering::Equal => println!("You win!"),
} }
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2478,6 +2501,7 @@ Let's add that in:
```{rust,no_run} ```{rust,no_run}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2507,17 +2531,17 @@ fn main() {
println!("You guessed: {}", num); println!("You guessed: {}", num);
match cmp(num, secret_number) { match cmp(num, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => println!("You win!"), Ordering::Equal => println!("You win!"),
} }
} }
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2553,6 +2577,7 @@ suboptimal to say the least. First, let's actually quit when you win the game:
```{rust,no_run} ```{rust,no_run}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2582,9 +2607,9 @@ fn main() {
println!("You guessed: {}", num); println!("You guessed: {}", num);
match cmp(num, secret_number) { match cmp(num, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => { Ordering::Equal => {
println!("You win!"); println!("You win!");
return; return;
}, },
@ -2593,9 +2618,9 @@ fn main() {
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2608,6 +2633,7 @@ we don't want to quit, we just want to ignore it. Change that `return` to
```{rust,no_run} ```{rust,no_run}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2637,9 +2663,9 @@ fn main() {
println!("You guessed: {}", num); println!("You guessed: {}", num);
match cmp(num, secret_number) { match cmp(num, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => { Ordering::Equal => {
println!("You win!"); println!("You win!");
return; return;
}, },
@ -2648,9 +2674,9 @@ fn main() {
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -2686,6 +2712,7 @@ It was good for testing, but it kind of ruins the game. Here's our final source:
```{rust,no_run} ```{rust,no_run}
use std::io; use std::io;
use std::rand; use std::rand;
use std::cmp::Ordering;
fn main() { fn main() {
println!("Guess the number!"); println!("Guess the number!");
@ -2713,9 +2740,9 @@ fn main() {
println!("You guessed: {}", num); println!("You guessed: {}", num);
match cmp(num, secret_number) { match cmp(num, secret_number) {
Less => println!("Too small!"), Ordering::Less => println!("Too small!"),
Greater => println!("Too big!"), Ordering::Greater => println!("Too big!"),
Equal => { Ordering::Equal => {
println!("You win!"); println!("You win!");
return; return;
}, },
@ -2724,9 +2751,9 @@ fn main() {
} }
fn cmp(a: uint, b: uint) -> Ordering { fn cmp(a: uint, b: uint) -> Ordering {
if a < b { Less } if a < b { Ordering::Less }
else if a > b { Greater } else if a > b { Ordering::Greater }
else { Equal } else { Ordering::Equal }
} }
``` ```
@ -5217,7 +5244,7 @@ as you can see, there's no overhead of deciding which version to call here,
hence 'statically dispatched'. The downside is that we have two copies of hence 'statically dispatched'. The downside is that we have two copies of
the same function, so our binary is a little bit larger. the same function, so our binary is a little bit larger.
# Threads # Threads
Concurrency and parallelism are topics that are of increasing interest to a Concurrency and parallelism are topics that are of increasing interest to a
broad subsection of software developers. Modern computers are often multi-core, broad subsection of software developers. Modern computers are often multi-core,

View File

@ -4149,11 +4149,11 @@ Unwinding the stack of a thread is done by the thread itself, on its own control
stack. If a value with a destructor is freed during unwinding, the code for the stack. If a value with a destructor is freed during unwinding, the code for the
destructor is run, also on the thread's control stack. Running the destructor destructor is run, also on the thread's control stack. Running the destructor
code causes a temporary transition to a *running* state, and allows the code causes a temporary transition to a *running* state, and allows the
destructor code to cause any subsequent state transitions. The original thread destructor code to cause any subsequent state transitions. The original thread
of unwinding and panicking thereby may suspend temporarily, and may involve of unwinding and panicking thereby may suspend temporarily, and may involve
(recursive) unwinding of the stack of a failed destructor. Nonetheless, the (recursive) unwinding of the stack of a failed destructor. Nonetheless, the
outermost unwinding activity will continue until the stack is unwound and the outermost unwinding activity will continue until the stack is unwound and the
thread transitions to the *dead* state. There is no way to "recover" from thread thread transitions to the *dead* state. There is no way to "recover" from thread
panics. Once a thread has temporarily suspended its unwinding in the *panicking* panics. Once a thread has temporarily suspended its unwinding in the *panicking*
state, a panic occurring from within this destructor results in *hard* panic. state, a panic occurring from within this destructor results in *hard* panic.
A hard panic currently results in the process aborting. A hard panic currently results in the process aborting.

View File

@ -26,6 +26,7 @@
//! [dir_graph]: http://en.wikipedia.org/wiki/Directed_graph //! [dir_graph]: http://en.wikipedia.org/wiki/Directed_graph
//! //!
//! ``` //! ```
//! use std::cmp::Ordering;
//! use std::collections::BinaryHeap; //! use std::collections::BinaryHeap;
//! use std::uint; //! use std::uint;
//! //!
@ -151,6 +152,7 @@
use core::prelude::*; use core::prelude::*;
use core::default::Default; use core::default::Default;
use core::iter::FromIterator;
use core::mem::{zeroed, replace, swap}; use core::mem::{zeroed, replace, swap};
use core::ptr; use core::ptr;

View File

@ -82,17 +82,19 @@
use core::prelude::*; use core::prelude::*;
use core::cmp::Ordering;
use core::cmp; use core::cmp;
use core::default::Default; use core::default::Default;
use core::fmt; use core::fmt;
use core::hash;
use core::iter::{Cloned, Chain, Enumerate, Repeat, Skip, Take, repeat}; use core::iter::{Cloned, Chain, Enumerate, Repeat, Skip, Take, repeat};
use core::iter; use core::iter::{mod, FromIterator, RandomAccessIterator};
use core::num::Int; use core::num::Int;
use core::slice; use core::ops::Index;
use core::slice::{Iter, IterMut};
use core::{u8, u32, uint}; use core::{u8, u32, uint};
use bitv_set; //so meta use bitv_set; //so meta
use core::hash;
use Vec; use Vec;
type Blocks<'a> = Cloned<slice::Iter<'a, u32>>; type Blocks<'a> = Cloned<slice::Iter<'a, u32>>;
@ -2507,7 +2509,7 @@ mod tests {
#[cfg(test)] #[cfg(test)]
mod bitv_bench { mod bitv_bench {
use std::prelude::*; use std::prelude::v1::*;
use std::rand; use std::rand;
use std::rand::Rng; use std::rand::Rng;
use std::u32; use std::u32;
@ -3002,7 +3004,7 @@ mod bitv_set_test {
#[cfg(test)] #[cfg(test)]
mod bitv_set_bench { mod bitv_set_bench {
use std::prelude::*; use std::prelude::v1::*;
use std::rand; use std::rand;
use std::rand::Rng; use std::rand::Rng;
use std::u32; use std::u32;

View File

@ -19,21 +19,23 @@ pub use self::Entry::*;
use core::prelude::*; use core::prelude::*;
use self::StackOp::*;
use super::node::{mod, Node, Found, GoDown};
use super::node::{Traversal, MutTraversal, MoveTraversal};
use super::node::TraversalItem::{mod, Elem, Edge};
use super::node::ForceResult::{Leaf, Internal};
use core::borrow::BorrowFrom; use core::borrow::BorrowFrom;
use std::hash::{Writer, Hash}; use core::cmp::Ordering;
use core::default::Default; use core::default::Default;
use core::{iter, fmt, mem};
use core::fmt::Show; use core::fmt::Show;
use core::iter::Map; use core::hash::{Writer, Hash};
use core::iter::{Map, FromIterator};
use core::ops::{Index, IndexMut};
use core::{iter, fmt, mem};
use ring_buf::RingBuf; use ring_buf::RingBuf;
use self::Continuation::{Continue, Finished}; use self::Continuation::{Continue, Finished};
use self::StackOp::*;
use super::node::ForceResult::{Leaf, Internal};
use super::node::TraversalItem::{mod, Elem, Edge};
use super::node::{Traversal, MutTraversal, MoveTraversal};
use super::node::{mod, Node, Found, GoDown};
// FIXME(conventions): implement bounded iterators // FIXME(conventions): implement bounded iterators
@ -501,6 +503,7 @@ mod stack {
use core::prelude::*; use core::prelude::*;
use core::kinds::marker; use core::kinds::marker;
use core::mem; use core::mem;
use core::ops::{Deref, DerefMut};
use super::BTreeMap; use super::BTreeMap;
use super::super::node::{mod, Node, Fit, Split, Internal, Leaf}; use super::super::node::{mod, Node, Fit, Split, Internal, Leaf};
use super::super::node::handle; use super::super::node::handle;

View File

@ -18,10 +18,12 @@ pub use self::TraversalItem::*;
use core::prelude::*; use core::prelude::*;
use core::{slice, mem, ptr, cmp, num, raw};
use core::iter::Zip;
use core::borrow::BorrowFrom; use core::borrow::BorrowFrom;
use core::cmp::Ordering::{Greater, Less, Equal};
use core::iter::Zip;
use core::ops::{Deref, DerefMut};
use core::ptr::Unique; use core::ptr::Unique;
use core::{slice, mem, ptr, cmp, num, raw};
use alloc::heap; use alloc::heap;
/// Represents the result of an Insertion: either the item fit, or the node had to split /// Represents the result of an Insertion: either the item fit, or the node had to split

View File

@ -13,13 +13,16 @@
use core::prelude::*; use core::prelude::*;
use btree_map::{BTreeMap, Keys};
use std::hash::Hash;
use core::borrow::BorrowFrom; use core::borrow::BorrowFrom;
use core::cmp::Ordering::{mod, Less, Greater, Equal};
use core::default::Default; use core::default::Default;
use core::fmt;
use core::iter::{Peekable, Map};
use core::fmt::Show; use core::fmt::Show;
use core::fmt;
use core::hash::Hash;
use core::iter::{Peekable, Map, FromIterator};
use core::ops::{BitOr, BitAnd, BitXor, Sub};
use btree_map::{BTreeMap, Keys};
// FIXME(conventions): implement bounded iterators // FIXME(conventions): implement bounded iterators

View File

@ -22,12 +22,13 @@
use core::prelude::*; use core::prelude::*;
use alloc::boxed::Box; use alloc::boxed::Box;
use core::cmp::Ordering;
use core::default::Default; use core::default::Default;
use core::fmt; use core::fmt;
use core::iter; use core::hash::{Writer, Hash};
use core::iter::{mod, FromIterator};
use core::mem; use core::mem;
use core::ptr; use core::ptr;
use std::hash::{Writer, Hash};
/// A doubly-linked list. /// A doubly-linked list.
#[stable] #[stable]

View File

@ -16,6 +16,8 @@
use core::prelude::*; use core::prelude::*;
use core::fmt; use core::fmt;
use core::num::Int; use core::num::Int;
use core::iter::FromIterator;
use core::ops::{Sub, BitOr, BitAnd, BitXor};
// FIXME(contentions): implement union family of methods? (general design may be wrong here) // FIXME(contentions): implement union family of methods? (general design may be wrong here)

View File

@ -14,14 +14,16 @@
use core::prelude::*; use core::prelude::*;
use core::cmp::Ordering;
use core::default::Default; use core::default::Default;
use core::fmt; use core::fmt;
use core::iter; use core::iter::{mod, FromIterator, RandomAccessIterator};
use core::raw::Slice as RawSlice;
use core::ptr;
use core::kinds::marker; use core::kinds::marker;
use core::mem; use core::mem;
use core::num::{Int, UnsignedInt}; use core::num::{Int, UnsignedInt};
use core::ops::{Index, IndexMut};
use core::ptr;
use core::raw::Slice as RawSlice;
use std::hash::{Writer, Hash}; use std::hash::{Writer, Hash};
use std::cmp; use std::cmp;

View File

@ -89,15 +89,19 @@
use alloc::boxed::Box; use alloc::boxed::Box;
use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned}; use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned};
use core::cmp; use core::clone::Clone;
use core::iter::{range_step, MultiplicativeIterator}; use core::cmp::Ordering::{mod, Greater, Less};
use core::cmp::{mod, Ord};
use core::iter::{Iterator, IteratorExt, IteratorCloneExt};
use core::iter::{range, range_step, MultiplicativeIterator};
use core::kinds::Sized; use core::kinds::Sized;
use core::mem::size_of; use core::mem::size_of;
use core::mem; use core::mem;
use core::ops::{FnMut,SliceMut}; use core::ops::{FnMut, SliceMut};
use core::prelude::{Clone, Greater, Iterator, IteratorExt, Less, None, Option}; use core::option::Option::{mod, Some, None};
use core::prelude::{Ord, Ordering, PtrExt, Some, range, IteratorCloneExt, Result}; use core::ptr::PtrExt;
use core::ptr; use core::ptr;
use core::result::Result;
use core::slice as core_slice; use core::slice as core_slice;
use self::Direction::*; use self::Direction::*;

View File

@ -17,12 +17,14 @@
use core::prelude::*; use core::prelude::*;
use core::borrow::{Cow, IntoCow}; use core::borrow::{Cow, IntoCow};
use core::cmp::Equiv;
use core::default::Default; use core::default::Default;
use core::fmt; use core::fmt;
use core::hash; use core::hash;
use core::iter::FromIterator;
use core::mem; use core::mem;
use core::ops::{mod, Deref, Add};
use core::ptr; use core::ptr;
use core::ops;
use core::raw::Slice as RawSlice; use core::raw::Slice as RawSlice;
use unicode::str as unicode_str; use unicode::str as unicode_str;
use unicode::str::Utf16Item; use unicode::str::Utf16Item;

View File

@ -50,14 +50,16 @@ use alloc::boxed::Box;
use alloc::heap::{EMPTY, allocate, reallocate, deallocate}; use alloc::heap::{EMPTY, allocate, reallocate, deallocate};
use core::borrow::{Cow, IntoCow}; use core::borrow::{Cow, IntoCow};
use core::cmp::max; use core::cmp::max;
use core::cmp::{Equiv, Ordering};
use core::default::Default; use core::default::Default;
use core::fmt; use core::fmt;
use core::hash::{mod, Hash}; use core::hash::{mod, Hash};
use core::iter::repeat; use core::iter::{repeat, FromIterator};
use core::kinds::marker::{ContravariantLifetime, InvariantType}; use core::kinds::marker::{ContravariantLifetime, InvariantType};
use core::mem; use core::mem;
use core::nonzero::NonZero; use core::nonzero::NonZero;
use core::num::{Int, UnsignedInt}; use core::num::{Int, UnsignedInt};
use core::ops::{Index, IndexMut, Deref, Add};
use core::ops; use core::ops;
use core::ptr; use core::ptr;
use core::raw::Slice as RawSlice; use core::raw::Slice as RawSlice;

View File

@ -15,12 +15,14 @@
use core::prelude::*; use core::prelude::*;
use core::cmp::Ordering;
use core::default::Default; use core::default::Default;
use core::fmt; use core::fmt;
use core::hash::{Hash, Writer}; use core::hash::{Hash, Writer};
use core::iter::{Enumerate, FilterMap, Map, FromIterator};
use core::iter; use core::iter;
use core::iter::{Enumerate, FilterMap, Map};
use core::mem::replace; use core::mem::replace;
use core::ops::{Index, IndexMut};
use {vec, slice}; use {vec, slice};
use vec::Vec; use vec::Vec;

View File

@ -125,11 +125,12 @@ impl Ordering {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::cmp::Ordering::{Less, Equal, Greater};
///
/// assert_eq!(Less.reverse(), Greater); /// assert_eq!(Less.reverse(), Greater);
/// assert_eq!(Equal.reverse(), Equal); /// assert_eq!(Equal.reverse(), Equal);
/// assert_eq!(Greater.reverse(), Less); /// assert_eq!(Greater.reverse(), Less);
/// ///
///
/// let mut data: &mut [_] = &mut [2u, 10, 5, 8]; /// let mut data: &mut [_] = &mut [2u, 10, 5, 8];
/// ///
/// // sort the array from largest to smallest. /// // sort the array from largest to smallest.
@ -170,6 +171,8 @@ pub trait Ord for Sized?: Eq + PartialOrd<Self> {
/// the expression `self <operator> other` if true. For example: /// the expression `self <operator> other` if true. For example:
/// ///
/// ``` /// ```
/// use std::cmp::Ordering::{Less, Equal, Greater};
///
/// assert_eq!( 5u.cmp(&10), Less); // because 5 < 10 /// assert_eq!( 5u.cmp(&10), Less); // because 5 < 10
/// assert_eq!(10u.cmp(&5), Greater); // because 10 > 5 /// assert_eq!(10u.cmp(&5), Greater); // because 10 > 5
/// assert_eq!( 5u.cmp(&5), Equal); // because 5 == 5 /// assert_eq!( 5u.cmp(&5), Equal); // because 5 == 5

View File

@ -25,6 +25,8 @@
//! demonstrates adding and subtracting two `Point`s. //! demonstrates adding and subtracting two `Point`s.
//! //!
//! ```rust //! ```rust
//! use std::ops::{Add, Sub};
//!
//! #[deriving(Show)] //! #[deriving(Show)]
//! struct Point { //! struct Point {
//! x: int, //! x: int,
@ -68,13 +70,13 @@ use option::Option::{mod, Some, None};
/// struct HasDrop; /// struct HasDrop;
/// ///
/// impl Drop for HasDrop { /// impl Drop for HasDrop {
/// fn drop(&mut self) { /// fn drop(&mut self) {
/// println!("Dropping!"); /// println!("Dropping!");
/// } /// }
/// } /// }
/// ///
/// fn main() { /// fn main() {
/// let _x = HasDrop; /// let _x = HasDrop;
/// } /// }
/// ``` /// ```
#[lang="drop"] #[lang="drop"]
@ -91,6 +93,8 @@ pub trait Drop {
/// calling `add`, and therefore, `main` prints `Adding!`. /// calling `add`, and therefore, `main` prints `Adding!`.
/// ///
/// ```rust /// ```rust
/// use std::ops::Add;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -130,6 +134,8 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// calling `sub`, and therefore, `main` prints `Subtracting!`. /// calling `sub`, and therefore, `main` prints `Subtracting!`.
/// ///
/// ```rust /// ```rust
/// use std::ops::Sub;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -169,6 +175,8 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// calling `mul`, and therefore, `main` prints `Multiplying!`. /// calling `mul`, and therefore, `main` prints `Multiplying!`.
/// ///
/// ```rust /// ```rust
/// use std::ops::Mul;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -208,6 +216,8 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// calling `div`, and therefore, `main` prints `Dividing!`. /// calling `div`, and therefore, `main` prints `Dividing!`.
/// ///
/// ``` /// ```
/// use std::ops::Div;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -247,6 +257,8 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
/// calling `rem`, and therefore, `main` prints `Remainder-ing!`. /// calling `rem`, and therefore, `main` prints `Remainder-ing!`.
/// ///
/// ``` /// ```
/// use std::ops::Rem;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -300,6 +312,8 @@ rem_float_impl! { f64, fmod }
/// `neg`, and therefore, `main` prints `Negating!`. /// `neg`, and therefore, `main` prints `Negating!`.
/// ///
/// ``` /// ```
/// use std::ops::Neg;
///
/// struct Foo; /// struct Foo;
/// ///
/// impl Copy for Foo {} /// impl Copy for Foo {}
@ -356,6 +370,8 @@ neg_uint_impl! { u64, i64 }
/// `not`, and therefore, `main` prints `Not-ing!`. /// `not`, and therefore, `main` prints `Not-ing!`.
/// ///
/// ``` /// ```
/// use std::ops::Not;
///
/// struct Foo; /// struct Foo;
/// ///
/// impl Copy for Foo {} /// impl Copy for Foo {}
@ -396,6 +412,8 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`. /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`.
/// ///
/// ``` /// ```
/// use std::ops::BitAnd;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -435,6 +453,8 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`. /// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
/// ///
/// ``` /// ```
/// use std::ops::BitOr;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -474,6 +494,8 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`. /// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
/// ///
/// ``` /// ```
/// use std::ops::BitXor;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -513,6 +535,8 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// calling `shl`, and therefore, `main` prints `Shifting left!`. /// calling `shl`, and therefore, `main` prints `Shifting left!`.
/// ///
/// ``` /// ```
/// use std::ops::Shl;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -554,6 +578,8 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// calling `shr`, and therefore, `main` prints `Shifting right!`. /// calling `shr`, and therefore, `main` prints `Shifting right!`.
/// ///
/// ``` /// ```
/// use std::ops::Shr;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -594,6 +620,8 @@ shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// calling `index`, and therefore, `main` prints `Indexing!`. /// calling `index`, and therefore, `main` prints `Indexing!`.
/// ///
/// ``` /// ```
/// use std::ops::Index;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -623,6 +651,8 @@ pub trait Index<Sized? Index, Sized? Result> for Sized? {
/// calling `index_mut`, and therefore, `main` prints `Indexing!`. /// calling `index_mut`, and therefore, `main` prints `Indexing!`.
/// ///
/// ``` /// ```
/// use std::ops::IndexMut;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -652,6 +682,8 @@ pub trait IndexMut<Sized? Index, Sized? Result> for Sized? {
/// calling `slice_to`, and therefore, `main` prints `Slicing!`. /// calling `slice_to`, and therefore, `main` prints `Slicing!`.
/// ///
/// ```ignore /// ```ignore
/// use std::ops::Slice;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -699,6 +731,8 @@ pub trait Slice<Sized? Idx, Sized? Result> for Sized? {
/// calling `slice_from_mut`, and therefore, `main` prints `Slicing!`. /// calling `slice_from_mut`, and therefore, `main` prints `Slicing!`.
/// ///
/// ```ignore /// ```ignore
/// use std::ops::SliceMut;
///
/// #[deriving(Copy)] /// #[deriving(Copy)]
/// struct Foo; /// struct Foo;
/// ///
@ -827,6 +861,8 @@ pub struct RangeTo<Idx> {
/// struct. /// struct.
/// ///
/// ``` /// ```
/// use std::ops::Deref;
///
/// struct DerefExample<T> { /// struct DerefExample<T> {
/// value: T /// value: T
/// } /// }
@ -865,6 +901,8 @@ impl<'a, Sized? T> Deref<T> for &'a mut T {
/// struct. /// struct.
/// ///
/// ``` /// ```
/// use std::ops::{Deref, DerefMut};
///
/// struct DerefMutExample<T> { /// struct DerefMutExample<T> {
/// value: T /// value: T
/// } /// }

View File

@ -30,39 +30,24 @@
// Reexported core operators // Reexported core operators
pub use kinds::{Copy, Send, Sized, Sync}; pub use kinds::{Copy, Send, Sized, Sync};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not}; pub use ops::{Drop, Fn, FnMut, FnOnce};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Drop, Deref, DerefMut};
pub use ops::{Shl, Shr};
pub use ops::{Index, IndexMut};
pub use ops::{Slice, SliceMut};
pub use ops::{Fn, FnMut, FnOnce};
// Reexported functions // Reexported functions
pub use iter::range; pub use iter::range;
pub use mem::drop; pub use mem::drop;
pub use str::from_str;
// Reexported types and traits // Reexported types and traits
pub use char::Char; pub use char::Char;
pub use clone::Clone; pub use clone::Clone;
pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
pub use cmp::{Ordering, Equiv}; pub use iter::{Extend, IteratorExt};
pub use cmp::Ordering::{Less, Equal, Greater}; pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt};
pub use iter::{FromIterator, Extend, IteratorExt}; pub use iter::{IteratorCloneExt, CloneIteratorExt};
pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt, RandomAccessIterator}; pub use iter::{IteratorOrdExt, ExactSizeIterator, IteratorPairExt};
pub use iter::{IteratorCloneExt, CloneIteratorExt, IteratorPairExt}; pub use option::Option::{mod, Some, None};
pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator, ExactSizeIterator};
pub use num::{ToPrimitive, FromPrimitive};
pub use option::Option;
pub use option::Option::{Some, None};
pub use ptr::{PtrExt, MutPtrExt}; pub use ptr::{PtrExt, MutPtrExt};
pub use result::Result; pub use result::Result::{mod, Ok, Err};
pub use result::Result::{Ok, Err};
pub use str::{Str, StrExt};
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
pub use slice::{PartialEqSliceExt, OrdSliceExt};
pub use slice::{AsSlice, SliceExt}; pub use slice::{AsSlice, SliceExt};
pub use slice::{PartialEqSliceExt, OrdSliceExt};
pub use str::{Str, StrExt};

View File

@ -32,35 +32,6 @@
//! * `PartialOrd` //! * `PartialOrd`
//! * `Ord` //! * `Ord`
//! * `Default` //! * `Default`
//!
//! # Examples
//!
//! Using methods:
//!
//! ```
//! #[allow(deprecated)]
//! # fn main() {
//! let pair = ("pi", 3.14f64);
//! assert_eq!(pair.val0(), "pi");
//! assert_eq!(pair.val1(), 3.14f64);
//! # }
//! ```
//!
//! Using traits implemented for tuples:
//!
//! ```
//! use std::default::Default;
//!
//! let a = (1i, 2i);
//! let b = (3i, 4i);
//! assert!(a != b);
//!
//! let c = b.clone();
//! assert!(b == c);
//!
//! let d : (u32, f32) = Default::default();
//! assert_eq!(d, (0u32, 0.0f32));
//! ```
#![stable] #![stable]

View File

@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use core::cmp::{ partial_min, partial_max }; use core::cmp::{partial_min, partial_max};
use core::cmp::Ordering::{Less, Greater, Equal};
#[test] #[test]
fn test_int_totalord() { fn test_int_totalord() {

View File

@ -17,6 +17,7 @@ mod tests {
use core::int; use core::int;
use core::num::{FromStrRadix, Int, SignedInt}; use core::num::{FromStrRadix, Int, SignedInt};
use core::str::from_str; use core::str::from_str;
use core::ops::{Shl, Shr, Not, BitXor, BitAnd, BitOr};
use num; use num;
#[test] #[test]

View File

@ -13,6 +13,7 @@ use core::fmt::Show;
use core::num::{NumCast, cast}; use core::num::{NumCast, cast};
use core::ops::{Add, Sub, Mul, Div, Rem}; use core::ops::{Add, Sub, Mul, Div, Rem};
use core::kinds::Copy; use core::kinds::Copy;
use std::str::from_str;
mod int_macros; mod int_macros;
mod i8; mod i8;
@ -54,6 +55,7 @@ mod test {
use core::option::Option::{Some, None}; use core::option::Option::{Some, None};
use core::num::Float; use core::num::Float;
use core::num::from_str_radix; use core::num::from_str_radix;
use core::str::from_str;
#[test] #[test]
fn from_str_issue7588() { fn from_str_issue7588() {

View File

@ -16,6 +16,7 @@ mod tests {
use core::$T_i::*; use core::$T_i::*;
use core::num::Int; use core::num::Int;
use num; use num;
use core::ops::{BitOr, BitAnd, BitXor, Shl, Shr, Not};
#[test] #[test]
fn test_overflows() { fn test_overflows() {

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::str::from_str;
#[test] #[test]
fn test_bool_from_str() { fn test_bool_from_str() {
assert_eq!(from_str::<bool>("true"), Some(true)); assert_eq!(from_str::<bool>("true"), Some(true));

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::cmp::Ordering::{Equal, Less, Greater};
#[test] #[test]
fn test_clone() { fn test_clone() {
let a = (1i, "2"); let a = (1i, "2");

View File

@ -47,6 +47,7 @@
//! which is cyclic. //! which is cyclic.
//! //!
//! ```rust //! ```rust
//! use std::borrow::IntoCow;
//! use graphviz as dot; //! use graphviz as dot;
//! //!
//! type Nd = int; //! type Nd = int;
@ -146,6 +147,7 @@
//! entity `&sube`). //! entity `&sube`).
//! //!
//! ```rust //! ```rust
//! use std::borrow::IntoCow;
//! use graphviz as dot; //! use graphviz as dot;
//! //!
//! type Nd = uint; //! type Nd = uint;
@ -201,6 +203,7 @@
//! Hasse-diagram for the subsets of the set `{x, y}`. //! Hasse-diagram for the subsets of the set `{x, y}`.
//! //!
//! ```rust //! ```rust
//! use std::borrow::IntoCow;
//! use graphviz as dot; //! use graphviz as dot;
//! //!
//! type Nd<'a> = (uint, &'a str); //! type Nd<'a> = (uint, &'a str);
@ -273,6 +276,7 @@
pub use self::LabelText::*; pub use self::LabelText::*;
use std::borrow::IntoCow;
use std::io; use std::io;
use std::str::CowString; use std::str::CowString;
use std::vec::CowVec; use std::vec::CowVec;
@ -586,6 +590,7 @@ mod tests {
use super::{Nodes, Edges, GraphWalk, render}; use super::{Nodes, Edges, GraphWalk, render};
use std::io::IoResult; use std::io::IoResult;
use std::str; use std::str;
use std::borrow::IntoCow;
/// each node is an index in a vector in the graph. /// each node is an index in a vector in the graph.
type Node = uint; type Node = uint;

View File

@ -12,8 +12,10 @@
pub use self::MaybeOwnedVector::*; pub use self::MaybeOwnedVector::*;
use std::cmp::{Equiv, Ordering};
use std::default::Default; use std::default::Default;
use std::fmt; use std::fmt;
use std::iter::FromIterator;
use std::path::BytesContainer; use std::path::BytesContainer;
use std::slice; use std::slice;
@ -125,7 +127,7 @@ impl<'a,T> FromIterator<T> for MaybeOwnedVector<'a,T> {
fn from_iter<I:Iterator<T>>(iterator: I) -> MaybeOwnedVector<'a,T> { fn from_iter<I:Iterator<T>>(iterator: I) -> MaybeOwnedVector<'a,T> {
// If we are building from scratch, might as well build the // If we are building from scratch, might as well build the
// most flexible variant. // most flexible variant.
Growable(FromIterator::from_iter(iterator)) Growable(iterator.collect())
} }
} }

View File

@ -206,7 +206,7 @@ impl Rand for ChaChaRng {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::prelude::*; use std::prelude::v1::*;
use core::iter::order; use core::iter::order;
use {Rng, SeedableRng}; use {Rng, SeedableRng};

View File

@ -94,7 +94,7 @@ impl IndependentSample<f64> for Exp {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::prelude::*; use std::prelude::v1::*;
use distributions::{Sample, IndependentSample}; use distributions::{Sample, IndependentSample};
use super::Exp; use super::Exp;
@ -124,7 +124,7 @@ mod test {
mod bench { mod bench {
extern crate test; extern crate test;
use std::prelude::*; use std::prelude::v1::*;
use self::test::Bencher; use self::test::Bencher;
use std::mem::size_of; use std::mem::size_of;

View File

@ -323,7 +323,7 @@ impl IndependentSample<f64> for StudentT {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::prelude::*; use std::prelude::v1::*;
use distributions::{Sample, IndependentSample}; use distributions::{Sample, IndependentSample};
use super::{ChiSquared, StudentT, FisherF}; use super::{ChiSquared, StudentT, FisherF};
@ -385,7 +385,7 @@ mod test {
#[cfg(test)] #[cfg(test)]
mod bench { mod bench {
extern crate test; extern crate test;
use std::prelude::*; use std::prelude::v1::*;
use self::test::Bencher; use self::test::Bencher;
use std::mem::size_of; use std::mem::size_of;
use distributions::IndependentSample; use distributions::IndependentSample;

View File

@ -258,7 +258,7 @@ fn ziggurat<R: Rng, P, Z>(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::prelude::*; use std::prelude::v1::*;
use {Rng, Rand}; use {Rng, Rand};
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample}; use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};

View File

@ -160,7 +160,7 @@ impl IndependentSample<f64> for LogNormal {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::prelude::*; use std::prelude::v1::*;
use distributions::{Sample, IndependentSample}; use distributions::{Sample, IndependentSample};
use super::{Normal, LogNormal}; use super::{Normal, LogNormal};
@ -200,7 +200,7 @@ mod tests {
#[cfg(test)] #[cfg(test)]
mod bench { mod bench {
extern crate test; extern crate test;
use std::prelude::*; use std::prelude::v1::*;
use self::test::Bencher; use self::test::Bencher;
use std::mem::size_of; use std::mem::size_of;
use distributions::{Sample}; use distributions::{Sample};

View File

@ -164,7 +164,7 @@ float_impl! { f64 }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::num::Int; use std::num::Int;
use std::prelude::*; use std::prelude::v1::*;
use distributions::{Sample, IndependentSample}; use distributions::{Sample, IndependentSample};
use super::Range; use super::Range;

View File

@ -487,7 +487,7 @@ impl Rand for Isaac64Rng {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::prelude::*; use std::prelude::v1::*;
use core::iter::order; use core::iter::order;
use {Rng, SeedableRng}; use {Rng, SeedableRng};

View File

@ -214,7 +214,7 @@ impl<T:Rand> Rand for Option<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::prelude::*; use std::prelude::v1::*;
use std::rand::{Rng, thread_rng, Open01, Closed01}; use std::rand::{Rng, thread_rng, Open01, Closed01};
struct ConstantRng(u64); struct ConstantRng(u64);

View File

@ -149,7 +149,7 @@ impl Default for ReseedWithDefault {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::prelude::*; use std::prelude::v1::*;
use core::iter::order; use core::iter::order;
use super::{ReseedingRng, ReseedWithDefault}; use super::{ReseedingRng, ReseedWithDefault};

View File

@ -11,6 +11,7 @@
pub use self::NamesIter::*; pub use self::NamesIter::*;
pub use self::Regex::*; pub use self::Regex::*;
use std::borrow::IntoCow;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::str::CowString; use std::str::CowString;

View File

@ -37,6 +37,7 @@ pub use self::MatchKind::*;
pub use self::StepState::*; pub use self::StepState::*;
use std::cmp; use std::cmp;
use std::cmp::Ordering::{mod, Less, Equal, Greater};
use std::mem; use std::mem;
use std::iter::repeat; use std::iter::repeat;
use std::slice::SliceExt; use std::slice::SliceExt;

View File

@ -36,10 +36,11 @@ use util::ppaux::{ty_to_string};
use util::nodemap::{FnvHashMap, NodeSet}; use util::nodemap::{FnvHashMap, NodeSet};
use lint::{Context, LintPass, LintArray}; use lint::{Context, LintPass, LintArray};
use std::{cmp, slice};
use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::num::SignedInt; use std::num::SignedInt;
use std::{cmp, slice};
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64}; use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::{abi, ast, ast_map}; use syntax::{abi, ast, ast_map};
use syntax::ast_util::is_shift_binop; use syntax::ast_util::is_shift_binop;
use syntax::attr::{mod, AttrMetaMethods}; use syntax::attr::{mod, AttrMetaMethods};

View File

@ -32,13 +32,15 @@ use middle::ty::{ImplContainer, TraitContainer};
use middle::ty::{mod, Ty}; use middle::ty::{mod, Ty};
use middle::astencode::vtable_decoder_helpers; use middle::astencode::vtable_decoder_helpers;
use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
use std::hash; use std::hash;
use std::io::extensions::u64_from_be_bytes; use std::io::extensions::u64_from_be_bytes;
use std::io; use std::io;
use std::collections::hash_map::HashMap; use std::num::FromPrimitive;
use std::rc::Rc; use std::rc::Rc;
use std::str; use std::str;
use rbml::reader; use rbml::reader;
use rbml; use rbml;
use serialize::Decodable; use serialize::Decodable;

View File

@ -25,7 +25,6 @@ use middle::ty::{mod, AsPredicate, Ty};
use std::rc::Rc; use std::rc::Rc;
use std::str; use std::str;
use std::string::String;
use syntax::abi; use syntax::abi;
use syntax::ast; use syntax::ast;
use syntax::parse::token; use syntax::parse::token;

View File

@ -11,7 +11,9 @@
/// This module provides linkage between rustc::middle::graph and /// This module provides linkage between rustc::middle::graph and
/// libgraphviz traits. /// libgraphviz traits.
/// For clarity, rename the graphviz crate locally to dot. use std::borrow::IntoCow;
// For clarity, rename the graphviz crate locally to dot.
use graphviz as dot; use graphviz as dot;
use syntax::ast; use syntax::ast;

View File

@ -24,8 +24,7 @@ use middle::pat_util::*;
use middle::ty::*; use middle::ty::*;
use middle::ty; use middle::ty;
use std::fmt; use std::fmt;
use std::iter::AdditiveIterator; use std::iter::{range_inclusive, AdditiveIterator, FromIterator, repeat};
use std::iter::{range_inclusive, repeat};
use std::num::Float; use std::num::Float;
use std::slice; use std::slice;
use syntax::ast::{mod, DUMMY_NODE_ID, NodeId, Pat}; use syntax::ast::{mod, DUMMY_NODE_ID, NodeId, Pat};

View File

@ -27,8 +27,8 @@ use syntax::ptr::P;
use syntax::visit::{mod, Visitor}; use syntax::visit::{mod, Visitor};
use syntax::{ast_map, ast_util, codemap}; use syntax::{ast_map, ast_util, codemap};
use std::rc::Rc;
use std::collections::hash_map::Entry::Vacant; use std::collections::hash_map::Entry::Vacant;
use std::rc::Rc;
// //
// This pass classifies expressions by their constant-ness. // This pass classifies expressions by their constant-ness.

View File

@ -33,8 +33,9 @@ use util::nodemap::{FnvHashMap, FnvHashSet};
use util::ppaux::Repr; use util::ppaux::Repr;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::u32; use std::cmp::Ordering::{mod, Less, Greater, Equal};
use std::iter::repeat; use std::iter::repeat;
use std::u32;
use syntax::ast; use syntax::ast;
mod doc; mod doc;

View File

@ -36,6 +36,7 @@ use syntax::visit::Visitor;
use syntax::visit; use syntax::visit;
use std::iter::Enumerate; use std::iter::Enumerate;
use std::num::FromPrimitive;
use std::slice; use std::slice;
// The actual lang items defined come at the end of this file in one handy table. // The actual lang items defined come at the end of this file in one handy table.

View File

@ -69,7 +69,7 @@ use util::nodemap::{FnvHashMap};
use arena::TypedArena; use arena::TypedArena;
use std::borrow::BorrowFrom; use std::borrow::BorrowFrom;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::cmp; use std::cmp::{mod, Ordering};
use std::fmt::{mod, Show}; use std::fmt::{mod, Show};
use std::hash::{Hash, sip, Writer}; use std::hash::{Hash, sip, Writer};
use std::mem; use std::mem;

View File

@ -394,6 +394,7 @@ macro_rules! cgoptions {
mod cgsetters { mod cgsetters {
use super::{CodegenOptions, Passes, SomePasses, AllPasses}; use super::{CodegenOptions, Passes, SomePasses, AllPasses};
use std::str::from_str;
$( $(
pub fn $opt(cg: &mut CodegenOptions, v: Option<&str>) -> bool { pub fn $opt(cg: &mut CodegenOptions, v: Option<&str>) -> bool {

View File

@ -33,7 +33,7 @@ impl<'tcx> MoveErrorCollector<'tcx> {
} }
pub fn report_potential_errors<'a>(&self, bccx: &BorrowckCtxt<'a, 'tcx>) { pub fn report_potential_errors<'a>(&self, bccx: &BorrowckCtxt<'a, 'tcx>) {
report_move_errors(bccx, self.errors.borrow().deref()) report_move_errors(bccx, &*self.errors.borrow())
} }
} }

View File

@ -24,6 +24,7 @@ use rustc::middle::cfg::{CFGIndex};
use rustc::middle::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit}; use rustc::middle::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
use rustc::middle::dataflow; use rustc::middle::dataflow;
use std::rc::Rc; use std::rc::Rc;
use std::borrow::IntoCow;
#[deriving(Show, Copy)] #[deriving(Show, Copy)]
pub enum Variant { pub enum Variant {

View File

@ -54,6 +54,8 @@ use rustc::metadata;
use rustc::DIAGNOSTICS; use rustc::DIAGNOSTICS;
use std::any::AnyRefExt; use std::any::AnyRefExt;
use std::cmp::Ordering::Equal;
use std::comm::channel;
use std::io; use std::io;
use std::iter::repeat; use std::iter::repeat;
use std::os; use std::os;

View File

@ -13,8 +13,9 @@
use libc; use libc;
use ArchiveRef; use ArchiveRef;
use std::raw; use std::c_str::ToCStr;
use std::mem; use std::mem;
use std::raw;
pub struct ArchiveRO { pub struct ArchiveRO {
ptr: ArchiveRef, ptr: ArchiveRef,

View File

@ -61,8 +61,9 @@ use syntax::parse::token::{mod, special_idents};
use syntax::codemap::{Span, DUMMY_SP}; use syntax::codemap::{Span, DUMMY_SP};
use syntax::visit::{mod, Visitor}; use syntax::visit::{mod, Visitor};
use std::rc::Rc;
use std::mem::replace; use std::mem::replace;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
// Specifies how duplicates should be handled when adding a child item if // Specifies how duplicates should be handled when adding a child item if
// another item exists with the same name in some namespace. // another item exists with the same name in some namespace.

View File

@ -17,6 +17,8 @@
// `use` directives. // `use` directives.
// //
use std::ops::{Deref, DerefMut};
use Resolver; use Resolver;
use Namespace::{TypeNS, ValueNS}; use Namespace::{TypeNS, ValueNS};

View File

@ -27,6 +27,7 @@ use rustc::middle::def::Export;
use syntax::ast; use syntax::ast;
use syntax::parse::token; use syntax::parse::token;
use std::ops::{Deref, DerefMut};
use std::rc::Rc; use std::rc::Rc;
struct ExportRecorder<'a, 'b:'a, 'tcx:'b> { struct ExportRecorder<'a, 'b:'a, 'tcx:'b> {

View File

@ -20,6 +20,7 @@ use rustc::util::common::time;
use libc; use libc;
use flate; use flate;
use std::c_str::ToCStr;
use std::iter; use std::iter;
use std::mem; use std::mem;
use std::num::Int; use std::num::Int;

View File

@ -23,6 +23,7 @@ use syntax::diagnostic;
use syntax::diagnostic::{Emitter, Handler, Level, mk_handler}; use syntax::diagnostic::{Emitter, Handler, Level, mk_handler};
use std::c_str::{ToCStr, CString}; use std::c_str::{ToCStr, CString};
use std::comm::channel;
use std::io::Command; use std::io::Command;
use std::io::fs; use std::io::fs;
use std::iter::Unfold; use std::iter::Unfold;

View File

@ -1202,8 +1202,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
let glob_map = &self.analysis.glob_map; let glob_map = &self.analysis.glob_map;
let glob_map = glob_map.as_ref().unwrap(); let glob_map = glob_map.as_ref().unwrap();
if glob_map.contains_key(&id) { if glob_map.contains_key(&id) {
let names = glob_map.index(&id); for n in glob_map[id].iter() {
for n in names.iter() {
if name_string.len() > 0 { if name_string.len() > 0 {
name_string.push_str(", "); name_string.push_str(", ");
} }

View File

@ -20,7 +20,7 @@ use trans::machine::llalign_of_pref;
use trans::type_::Type; use trans::type_::Type;
use util::nodemap::FnvHashMap; use util::nodemap::FnvHashMap;
use libc::{c_uint, c_char}; use libc::{c_uint, c_char};
use std::string::String; use std::c_str::ToCStr;
use syntax::codemap::Span; use syntax::codemap::Span;
pub struct Builder<'a, 'tcx: 'a> { pub struct Builder<'a, 'tcx: 'a> {

View File

@ -26,6 +26,7 @@ use trans::type_of;
use middle::ty::{mod, Ty}; use middle::ty::{mod, Ty};
use middle::subst::{Substs}; use middle::subst::{Substs};
use std::cmp; use std::cmp;
use std::c_str::ToCStr;
use libc::c_uint; use libc::c_uint;
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi}; use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
use syntax::abi::{RustIntrinsic, Rust, RustCall, Stdcall, Fastcall, System}; use syntax::abi::{RustIntrinsic, Rust, RustCall, Stdcall, Fastcall, System};

View File

@ -18,10 +18,10 @@
pub use self::imp::Lock; pub use self::imp::Lock;
#[cfg(unix)] #[cfg(unix)]
mod imp { mod imp {
use libc; use libc;
use std::c_str::ToCStr;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
mod os { mod os {

View File

@ -29,11 +29,12 @@
use libc; use libc;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::c_str::ToCStr;
use std::cell::{RefCell, Cell}; use std::cell::{RefCell, Cell};
use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::slice; use std::slice;
use std::str; use std::str;
use std::collections::HashMap;
use html::toc::TocBuilder; use html::toc::TocBuilder;
use html::highlight; use html::highlight;

View File

@ -35,6 +35,7 @@
pub use self::ExternalLocation::*; pub use self::ExternalLocation::*;
use std::cell::RefCell; use std::cell::RefCell;
use std::cmp::Ordering::{mod, Less, Greater, Equal};
use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::default::Default; use std::default::Default;

View File

@ -13,8 +13,9 @@
//! hierarchy, with item counts for every stability level per module. A parent //! hierarchy, with item counts for every stability level per module. A parent
//! module's count includes its children's. //! module's count includes its children's.
use std::ops::Add; use std::cmp::Ordering;
use std::num::Zero; use std::num::Zero;
use std::ops::Add;
use syntax::attr::{Deprecated, Experimental, Unstable, Stable, Frozen, Locked}; use syntax::attr::{Deprecated, Experimental, Unstable, Stable, Frozen, Locked};
use syntax::ast::Public; use syntax::ast::Public;

View File

@ -9,14 +9,14 @@
// except according to those terms. // except according to those terms.
use std::cell::RefCell; use std::cell::RefCell;
use std::comm::channel;
use std::dynamic_lib::DynamicLibrary; use std::dynamic_lib::DynamicLibrary;
use std::io::{Command, TempDir}; use std::io::{Command, TempDir};
use std::io; use std::io;
use std::os; use std::os;
use std::str; use std::str;
use std::string::String;
use std::thunk::Thunk;
use std::thread::Thread; use std::thread::Thread;
use std::thunk::Thunk;
use std::collections::{HashSet, HashMap}; use std::collections::{HashSet, HashMap};
use testing; use testing;

View File

@ -315,8 +315,8 @@ static ASCII_UPPERCASE_MAP: [u8; 256] = [
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use prelude::v1::*;
use super::*; use super::*;
use prelude::*;
use char::from_u32; use char::from_u32;
#[test] #[test]

View File

@ -209,7 +209,7 @@ macro_rules! bitflags {
} }
} }
impl BitOr<$BitFlags, $BitFlags> for $BitFlags { impl ::std::ops::BitOr<$BitFlags, $BitFlags> for $BitFlags {
/// Returns the union of the two sets of flags. /// Returns the union of the two sets of flags.
#[inline] #[inline]
fn bitor(self, other: $BitFlags) -> $BitFlags { fn bitor(self, other: $BitFlags) -> $BitFlags {
@ -217,7 +217,7 @@ macro_rules! bitflags {
} }
} }
impl BitXor<$BitFlags, $BitFlags> for $BitFlags { impl ::std::ops::BitXor<$BitFlags, $BitFlags> for $BitFlags {
/// Returns the left flags, but with all the right flags toggled. /// Returns the left flags, but with all the right flags toggled.
#[inline] #[inline]
fn bitxor(self, other: $BitFlags) -> $BitFlags { fn bitxor(self, other: $BitFlags) -> $BitFlags {
@ -225,7 +225,7 @@ macro_rules! bitflags {
} }
} }
impl BitAnd<$BitFlags, $BitFlags> for $BitFlags { impl ::std::ops::BitAnd<$BitFlags, $BitFlags> for $BitFlags {
/// Returns the intersection between the two sets of flags. /// Returns the intersection between the two sets of flags.
#[inline] #[inline]
fn bitand(self, other: $BitFlags) -> $BitFlags { fn bitand(self, other: $BitFlags) -> $BitFlags {
@ -233,7 +233,7 @@ macro_rules! bitflags {
} }
} }
impl Sub<$BitFlags, $BitFlags> for $BitFlags { impl ::std::ops::Sub<$BitFlags, $BitFlags> for $BitFlags {
/// Returns the set difference of the two sets of flags. /// Returns the set difference of the two sets of flags.
#[inline] #[inline]
fn sub(self, other: $BitFlags) -> $BitFlags { fn sub(self, other: $BitFlags) -> $BitFlags {
@ -241,7 +241,7 @@ macro_rules! bitflags {
} }
} }
impl Not<$BitFlags> for $BitFlags { impl ::std::ops::Not<$BitFlags> for $BitFlags {
/// Returns the complement of this set of flags. /// Returns the complement of this set of flags.
#[inline] #[inline]
fn not(self) -> $BitFlags { fn not(self) -> $BitFlags {

View File

@ -45,6 +45,8 @@
//! ```rust //! ```rust
//! extern crate libc; //! extern crate libc;
//! //!
//! use std::c_str::ToCStr;
//!
//! extern { //! extern {
//! fn puts(s: *const libc::c_char); //! fn puts(s: *const libc::c_char);
//! } //! }
@ -70,6 +72,7 @@
use core::prelude::*; use core::prelude::*;
use libc; use libc;
use cmp::Ordering;
use fmt; use fmt;
use hash; use hash;
use mem; use mem;
@ -155,6 +158,8 @@ impl CString {
/// one). /// one).
/// ///
/// ```rust /// ```rust
/// use std::c_str::ToCStr;
///
/// let foo = "some string"; /// let foo = "some string";
/// ///
/// // right /// // right
@ -170,6 +175,8 @@ impl CString {
/// ```rust /// ```rust
/// extern crate libc; /// extern crate libc;
/// ///
/// use std::c_str::ToCStr;
///
/// fn main() { /// fn main() {
/// let c_str = "foo bar".to_c_str(); /// let c_str = "foo bar".to_c_str();
/// unsafe { /// unsafe {
@ -189,6 +196,8 @@ impl CString {
/// one). /// one).
/// ///
/// ```rust /// ```rust
/// use std::c_str::ToCStr;
///
/// let foo = "some string"; /// let foo = "some string";
/// ///
/// // right /// // right
@ -309,6 +318,8 @@ pub trait ToCStr for Sized? {
/// ```rust /// ```rust
/// extern crate libc; /// extern crate libc;
/// ///
/// use std::c_str::ToCStr;
///
/// fn main() { /// fn main() {
/// let s = "PATH".with_c_str(|path| unsafe { /// let s = "PATH".with_c_str(|path| unsafe {
/// libc::getenv(path) /// libc::getenv(path)
@ -539,8 +550,7 @@ pub unsafe fn from_c_multistring<F>(buf: *const libc::c_char,
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use prelude::{spawn, Some, None, Option, FnOnce, ToString, CloneSliceExt}; use prelude::v1::*;
use prelude::{Clone, PtrExt, Iterator, SliceExt, StrExt};
use ptr; use ptr;
use thread::Thread; use thread::Thread;
use libc; use libc;
@ -732,9 +742,10 @@ mod tests {
mod bench { mod bench {
extern crate test; extern crate test;
use prelude::v1::*;
use self::test::Bencher; use self::test::Bencher;
use libc; use libc;
use prelude::*; use c_str::ToCStr;
#[inline] #[inline]
fn check(s: &str, c_str: *const libc::c_char) { fn check(s: &str, c_str: *const libc::c_char) {

View File

@ -172,7 +172,7 @@ impl<T> AsSlice<T> for CVec<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use prelude::*; use prelude::v1::*;
use super::CVec; use super::CVec;
use libc; use libc;

View File

@ -11,7 +11,7 @@
#![cfg(test)] #![cfg(test)]
extern crate test; extern crate test;
use prelude::*; use prelude::v1::*;
use self::test::Bencher; use self::test::Bencher;
use iter::{range_inclusive}; use iter::{range_inclusive};

View File

@ -87,7 +87,7 @@ impl DefaultResizePolicy {
#[test] #[test]
fn test_resize_policy() { fn test_resize_policy() {
use prelude::*; use prelude::v1::*;
let rp = DefaultResizePolicy; let rp = DefaultResizePolicy;
for n in range(0u, 1000) { for n in range(0u, 1000) {
assert!(rp.min_capacity(rp.usable_capacity(n)) <= n); assert!(rp.min_capacity(rp.usable_capacity(n)) <= n);
@ -1530,8 +1530,9 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Extend<(K, V)> for HashMap<K
#[cfg(test)] #[cfg(test)]
mod test_map { mod test_map {
use prelude::*; use prelude::v1::*;
use cmp::Equiv;
use super::HashMap; use super::HashMap;
use super::Entry::{Occupied, Vacant}; use super::Entry::{Occupied, Vacant};
use hash; use hash;

View File

@ -866,7 +866,7 @@ impl<'a, T, S, H> Iterator<&'a T> for Union<'a, T, H>
#[cfg(test)] #[cfg(test)]
mod test_set { mod test_set {
use prelude::*; use prelude::v1::*;
use super::HashSet; use super::HashSet;

File diff suppressed because it is too large Load Diff

View File

@ -153,11 +153,12 @@ impl<T: Send> Drop for Queue<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use prelude::*; use prelude::v1::*;
use alloc::arc::Arc;
use comm::channel;
use super::{Queue, Data, Empty, Inconsistent}; use super::{Queue, Data, Empty, Inconsistent};
use sync::Arc;
use thread::Thread;
#[test] #[test]
fn test_full() { fn test_full() {
@ -181,12 +182,12 @@ mod tests {
for _ in range(0, nthreads) { for _ in range(0, nthreads) {
let tx = tx.clone(); let tx = tx.clone();
let q = q.clone(); let q = q.clone();
spawn(move|| { Thread::spawn(move|| {
for i in range(0, nmsgs) { for i in range(0, nmsgs) {
q.push(i); q.push(i);
} }
tx.send(()); tx.send(());
}); }).detach();
} }
let mut i = 0u; let mut i = 0u;

View File

@ -27,6 +27,8 @@
//! # Example //! # Example
//! //!
//! ```rust //! ```rust
//! use std::comm::channel;
//!
//! let (tx1, rx1) = channel(); //! let (tx1, rx1) = channel();
//! let (tx2, rx2) = channel(); //! let (tx2, rx2) = channel();
//! //!
@ -335,9 +337,10 @@ impl Iterator<*mut Handle<'static, ()>> for Packets {
#[cfg(test)] #[cfg(test)]
#[allow(unused_imports)] #[allow(unused_imports)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use super::*; use comm::*;
use thread::Thread;
// Don't use the libstd version so we can pull in the right Select structure // Don't use the libstd version so we can pull in the right Select structure
// (std::comm points at the wrong one) // (std::comm points at the wrong one)
@ -357,7 +360,8 @@ mod test {
}) })
} }
test! { fn smoke() { #[test]
fn smoke() {
let (tx1, rx1) = channel::<int>(); let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>(); let (tx2, rx2) = channel::<int>();
tx1.send(1); tx1.send(1);
@ -379,9 +383,10 @@ mod test {
select! { select! {
bar = rx2.recv_opt() => { assert_eq!(bar, Err(())); } bar = rx2.recv_opt() => { assert_eq!(bar, Err(())); }
} }
} } }
test! { fn smoke2() { #[test]
fn smoke2() {
let (_tx1, rx1) = channel::<int>(); let (_tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>(); let (_tx2, rx2) = channel::<int>();
let (_tx3, rx3) = channel::<int>(); let (_tx3, rx3) = channel::<int>();
@ -395,9 +400,10 @@ mod test {
_foo = rx4.recv() => { panic!("4") }, _foo = rx4.recv() => { panic!("4") },
foo = rx5.recv() => { assert_eq!(foo, 4); } foo = rx5.recv() => { assert_eq!(foo, 4); }
} }
} } }
test! { fn closed() { #[test]
fn closed() {
let (_tx1, rx1) = channel::<int>(); let (_tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>(); let (tx2, rx2) = channel::<int>();
drop(tx2); drop(tx2);
@ -406,14 +412,15 @@ mod test {
_a1 = rx1.recv_opt() => { panic!() }, _a1 = rx1.recv_opt() => { panic!() },
a2 = rx2.recv_opt() => { assert_eq!(a2, Err(())); } a2 = rx2.recv_opt() => { assert_eq!(a2, Err(())); }
} }
} } }
test! { fn unblocks() { #[test]
fn unblocks() {
let (tx1, rx1) = channel::<int>(); let (tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>(); let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<int>(); let (tx3, rx3) = channel::<int>();
spawn(move|| { let _t = Thread::spawn(move|| {
for _ in range(0u, 20) { Thread::yield_now(); } for _ in range(0u, 20) { Thread::yield_now(); }
tx1.send(1); tx1.send(1);
rx3.recv(); rx3.recv();
@ -429,14 +436,15 @@ mod test {
a = rx1.recv_opt() => { assert_eq!(a, Err(())); }, a = rx1.recv_opt() => { assert_eq!(a, Err(())); },
_b = rx2.recv() => { panic!() } _b = rx2.recv() => { panic!() }
} }
} } }
test! { fn both_ready() { #[test]
fn both_ready() {
let (tx1, rx1) = channel::<int>(); let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>(); let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>(); let (tx3, rx3) = channel::<()>();
spawn(move|| { let _t = Thread::spawn(move|| {
for _ in range(0u, 20) { Thread::yield_now(); } for _ in range(0u, 20) { Thread::yield_now(); }
tx1.send(1); tx1.send(1);
tx2.send(2); tx2.send(2);
@ -454,15 +462,16 @@ mod test {
assert_eq!(rx1.try_recv(), Err(Empty)); assert_eq!(rx1.try_recv(), Err(Empty));
assert_eq!(rx2.try_recv(), Err(Empty)); assert_eq!(rx2.try_recv(), Err(Empty));
tx3.send(()); tx3.send(());
} } }
test! { fn stress() { #[test]
fn stress() {
static AMT: int = 10000; static AMT: int = 10000;
let (tx1, rx1) = channel::<int>(); let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>(); let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>(); let (tx3, rx3) = channel::<()>();
spawn(move|| { let _t = Thread::spawn(move|| {
for i in range(0, AMT) { for i in range(0, AMT) {
if i % 2 == 0 { if i % 2 == 0 {
tx1.send(i); tx1.send(i);
@ -480,14 +489,15 @@ mod test {
} }
tx3.send(()); tx3.send(());
} }
} } }
test! { fn cloning() { #[test]
fn cloning() {
let (tx1, rx1) = channel::<int>(); let (tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>(); let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>(); let (tx3, rx3) = channel::<()>();
spawn(move|| { let _t = Thread::spawn(move|| {
rx3.recv(); rx3.recv();
tx1.clone(); tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty)); assert_eq!(rx3.try_recv(), Err(Empty));
@ -501,14 +511,15 @@ mod test {
_i2 = rx2.recv() => panic!() _i2 = rx2.recv() => panic!()
} }
tx3.send(()); tx3.send(());
} } }
test! { fn cloning2() { #[test]
fn cloning2() {
let (tx1, rx1) = channel::<int>(); let (tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>(); let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>(); let (tx3, rx3) = channel::<()>();
spawn(move|| { let _t = Thread::spawn(move|| {
rx3.recv(); rx3.recv();
tx1.clone(); tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty)); assert_eq!(rx3.try_recv(), Err(Empty));
@ -522,13 +533,14 @@ mod test {
_i2 = rx2.recv() => panic!() _i2 = rx2.recv() => panic!()
} }
tx3.send(()); tx3.send(());
} } }
test! { fn cloning3() { #[test]
fn cloning3() {
let (tx1, rx1) = channel::<()>(); let (tx1, rx1) = channel::<()>();
let (tx2, rx2) = channel::<()>(); let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>(); let (tx3, rx3) = channel::<()>();
spawn(move|| { let _t = Thread::spawn(move|| {
let s = Select::new(); let s = Select::new();
let mut h1 = s.handle(&rx1); let mut h1 = s.handle(&rx1);
let mut h2 = s.handle(&rx2); let mut h2 = s.handle(&rx2);
@ -542,44 +554,49 @@ mod test {
drop(tx1.clone()); drop(tx1.clone());
tx2.send(()); tx2.send(());
rx3.recv(); rx3.recv();
} } }
test! { fn preflight1() { #[test]
fn preflight1() {
let (tx, rx) = channel(); let (tx, rx) = channel();
tx.send(()); tx.send(());
select! { select! {
() = rx.recv() => {} () = rx.recv() => {}
} }
} } }
test! { fn preflight2() { #[test]
fn preflight2() {
let (tx, rx) = channel(); let (tx, rx) = channel();
tx.send(()); tx.send(());
tx.send(()); tx.send(());
select! { select! {
() = rx.recv() => {} () = rx.recv() => {}
} }
} } }
test! { fn preflight3() { #[test]
fn preflight3() {
let (tx, rx) = channel(); let (tx, rx) = channel();
drop(tx.clone()); drop(tx.clone());
tx.send(()); tx.send(());
select! { select! {
() = rx.recv() => {} () = rx.recv() => {}
} }
} } }
test! { fn preflight4() { #[test]
fn preflight4() {
let (tx, rx) = channel(); let (tx, rx) = channel();
tx.send(()); tx.send(());
let s = Select::new(); let s = Select::new();
let mut h = s.handle(&rx); let mut h = s.handle(&rx);
unsafe { h.add(); } unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id); assert_eq!(s.wait2(false), h.id);
} } }
test! { fn preflight5() { #[test]
fn preflight5() {
let (tx, rx) = channel(); let (tx, rx) = channel();
tx.send(()); tx.send(());
tx.send(()); tx.send(());
@ -587,9 +604,10 @@ mod test {
let mut h = s.handle(&rx); let mut h = s.handle(&rx);
unsafe { h.add(); } unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id); assert_eq!(s.wait2(false), h.id);
} } }
test! { fn preflight6() { #[test]
fn preflight6() {
let (tx, rx) = channel(); let (tx, rx) = channel();
drop(tx.clone()); drop(tx.clone());
tx.send(()); tx.send(());
@ -597,18 +615,20 @@ mod test {
let mut h = s.handle(&rx); let mut h = s.handle(&rx);
unsafe { h.add(); } unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id); assert_eq!(s.wait2(false), h.id);
} } }
test! { fn preflight7() { #[test]
fn preflight7() {
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
drop(tx); drop(tx);
let s = Select::new(); let s = Select::new();
let mut h = s.handle(&rx); let mut h = s.handle(&rx);
unsafe { h.add(); } unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id); assert_eq!(s.wait2(false), h.id);
} } }
test! { fn preflight8() { #[test]
fn preflight8() {
let (tx, rx) = channel(); let (tx, rx) = channel();
tx.send(()); tx.send(());
drop(tx); drop(tx);
@ -617,9 +637,10 @@ mod test {
let mut h = s.handle(&rx); let mut h = s.handle(&rx);
unsafe { h.add(); } unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id); assert_eq!(s.wait2(false), h.id);
} } }
test! { fn preflight9() { #[test]
fn preflight9() {
let (tx, rx) = channel(); let (tx, rx) = channel();
drop(tx.clone()); drop(tx.clone());
tx.send(()); tx.send(());
@ -629,12 +650,13 @@ mod test {
let mut h = s.handle(&rx); let mut h = s.handle(&rx);
unsafe { h.add(); } unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id); assert_eq!(s.wait2(false), h.id);
} } }
test! { fn oneshot_data_waiting() { #[test]
fn oneshot_data_waiting() {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
select! { select! {
() = rx1.recv() => {} () = rx1.recv() => {}
} }
@ -644,16 +666,17 @@ mod test {
for _ in range(0u, 100) { Thread::yield_now() } for _ in range(0u, 100) { Thread::yield_now() }
tx1.send(()); tx1.send(());
rx2.recv(); rx2.recv();
} } }
test! { fn stream_data_waiting() { #[test]
fn stream_data_waiting() {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
tx1.send(()); tx1.send(());
tx1.send(()); tx1.send(());
rx1.recv(); rx1.recv();
rx1.recv(); rx1.recv();
spawn(move|| { let _t = Thread::spawn(move|| {
select! { select! {
() = rx1.recv() => {} () = rx1.recv() => {}
} }
@ -663,15 +686,16 @@ mod test {
for _ in range(0u, 100) { Thread::yield_now() } for _ in range(0u, 100) { Thread::yield_now() }
tx1.send(()); tx1.send(());
rx2.recv(); rx2.recv();
} } }
test! { fn shared_data_waiting() { #[test]
fn shared_data_waiting() {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
drop(tx1.clone()); drop(tx1.clone());
tx1.send(()); tx1.send(());
rx1.recv(); rx1.recv();
spawn(move|| { let _t = Thread::spawn(move|| {
select! { select! {
() = rx1.recv() => {} () = rx1.recv() => {}
} }
@ -681,32 +705,35 @@ mod test {
for _ in range(0u, 100) { Thread::yield_now() } for _ in range(0u, 100) { Thread::yield_now() }
tx1.send(()); tx1.send(());
rx2.recv(); rx2.recv();
} } }
test! { fn sync1() { #[test]
fn sync1() {
let (tx, rx) = sync_channel::<int>(1); let (tx, rx) = sync_channel::<int>(1);
tx.send(1); tx.send(1);
select! { select! {
n = rx.recv() => { assert_eq!(n, 1); } n = rx.recv() => { assert_eq!(n, 1); }
} }
} } }
test! { fn sync2() { #[test]
fn sync2() {
let (tx, rx) = sync_channel::<int>(0); let (tx, rx) = sync_channel::<int>(0);
spawn(move|| { let _t = Thread::spawn(move|| {
for _ in range(0u, 100) { Thread::yield_now() } for _ in range(0u, 100) { Thread::yield_now() }
tx.send(1); tx.send(1);
}); });
select! { select! {
n = rx.recv() => { assert_eq!(n, 1); } n = rx.recv() => { assert_eq!(n, 1); }
} }
} } }
test! { fn sync3() { #[test]
fn sync3() {
let (tx1, rx1) = sync_channel::<int>(0); let (tx1, rx1) = sync_channel::<int>(0);
let (tx2, rx2): (Sender<int>, Receiver<int>) = channel(); let (tx2, rx2): (Sender<int>, Receiver<int>) = channel();
spawn(move|| { tx1.send(1); }); let _t = Thread::spawn(move|| { tx1.send(1); });
spawn(move|| { tx2.send(2); }); let _t = Thread::spawn(move|| { tx2.send(2); });
select! { select! {
n = rx1.recv() => { n = rx1.recv() => {
assert_eq!(n, 1); assert_eq!(n, 1);
@ -717,5 +744,5 @@ mod test {
assert_eq!(rx1.recv(), 1); assert_eq!(rx1.recv(), 1);
} }
} }
} } }
} }

View File

@ -240,10 +240,12 @@ impl<T: Send> Drop for Queue<T> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use sync::Arc; use sync::Arc;
use super::Queue; use super::Queue;
use thread::Thread;
use comm::channel;
#[test] #[test]
fn smoke() { fn smoke() {
@ -320,7 +322,7 @@ mod test {
let (tx, rx) = channel(); let (tx, rx) = channel();
let q2 = q.clone(); let q2 = q.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
for _ in range(0u, 100000) { for _ in range(0u, 100000) {
loop { loop {
match q2.pop() { match q2.pop() {

View File

@ -15,7 +15,9 @@
#![experimental] #![experimental]
#![allow(missing_docs)] #![allow(missing_docs)]
use prelude::*; use prelude::v1::*;
use c_str::ToCStr;
use mem; use mem;
use os; use os;
use str; use str;
@ -146,7 +148,7 @@ impl DynamicLibrary {
#[cfg(all(test, not(target_os = "ios")))] #[cfg(all(test, not(target_os = "ios")))]
mod test { mod test {
use super::*; use super::*;
use prelude::*; use prelude::v1::*;
use libc; use libc;
use mem; use mem;
@ -202,8 +204,8 @@ mod test {
pub mod dl { pub mod dl {
use self::Rtld::*; use self::Rtld::*;
use prelude::*; use prelude::v1::*;
use c_str::CString; use c_str::{CString, ToCStr};
use libc; use libc;
use ptr; use ptr;

View File

@ -78,7 +78,7 @@
//! } //! }
//! ``` //! ```
use prelude::*; use prelude::v1::*;
use str::Utf8Error; use str::Utf8Error;
use string::{FromUtf8Error, FromUtf16Error}; use string::{FromUtf8Error, FromUtf16Error};

View File

@ -10,7 +10,7 @@
#![experimental] #![experimental]
use prelude::*; use prelude::v1::*;
use any::{Any, AnyRefExt}; use any::{Any, AnyRefExt};
use cell::RefCell; use cell::RefCell;

View File

@ -410,7 +410,7 @@ impl<S: Stream> Writer for BufferedStream<S> {
mod test { mod test {
extern crate test; extern crate test;
use io; use io;
use prelude::*; use prelude::v1::*;
use super::*; use super::*;
use super::super::{IoResult, EndOfFile}; use super::super::{IoResult, EndOfFile};
use super::super::mem::MemReader; use super::super::mem::MemReader;

View File

@ -23,6 +23,7 @@ use vec::Vec;
/// # Example /// # Example
/// ///
/// ``` /// ```
/// use std::comm::channel;
/// use std::io::ChanReader; /// use std::io::ChanReader;
/// ///
/// let (tx, rx) = channel(); /// let (tx, rx) = channel();
@ -114,6 +115,7 @@ impl Reader for ChanReader {
/// ///
/// ``` /// ```
/// # #![allow(unused_must_use)] /// # #![allow(unused_must_use)]
/// use std::comm::channel;
/// use std::io::ChanWriter; /// use std::io::ChanWriter;
/// ///
/// let (tx, rx) = channel(); /// let (tx, rx) = channel();
@ -154,7 +156,9 @@ impl Writer for ChanWriter {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use comm::channel;
use super::*; use super::*;
use io; use io;
use thread::Thread; use thread::Thread;

View File

@ -175,7 +175,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use io; use io;
use io::{MemReader, BytesReader}; use io::{MemReader, BytesReader};
@ -507,7 +507,7 @@ mod test {
mod bench { mod bench {
extern crate test; extern crate test;
use prelude::*; use prelude::v1::*;
use self::test::Bencher; use self::test::Bencher;
// why is this a macro? wouldn't an inlined function work just as well? // why is this a macro? wouldn't an inlined function work just as well?

View File

@ -819,7 +819,7 @@ fn access_string(access: FileAccess) -> &'static str {
#[allow(unused_variables)] #[allow(unused_variables)]
#[allow(unused_mut)] #[allow(unused_mut)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType}; use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType};
use io; use io;
use str; use str;

View File

@ -399,9 +399,10 @@ impl<'a> Buffer for BufReader<'a> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
extern crate "test" as test_crate; extern crate "test" as test_crate;
use prelude::v1::*;
use super::*; use super::*;
use io::{SeekSet, SeekCur, SeekEnd, Reader, Writer, Seek}; use io::{SeekSet, SeekCur, SeekEnd};
use prelude::{Ok, Err, range, Vec, Buffer, AsSlice, SliceExt, IteratorExt, CloneSliceExt};
use io; use io;
use self::test_crate::Bencher; use self::test_crate::Bencher;

View File

@ -233,7 +233,7 @@ use fmt;
use int; use int;
use iter::{Iterator, IteratorExt}; use iter::{Iterator, IteratorExt};
use mem::transmute; use mem::transmute;
use ops::{BitOr, BitXor, BitAnd, Sub, Not, FnOnce}; use ops::FnOnce;
use option::Option; use option::Option;
use option::Option::{Some, None}; use option::Option::{Some, None};
use os; use os;
@ -1918,8 +1918,8 @@ impl fmt::Show for FilePermission {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use self::BadReaderBehavior::*; use self::BadReaderBehavior::*;
use super::{IoResult, Reader, MemReader, NoProgress, InvalidInput, Writer}; use super::{IoResult, MemReader, NoProgress, InvalidInput};
use prelude::{Ok, Vec, Buffer, CloneSliceExt}; use prelude::v1::*;
use uint; use uint;
#[deriving(Clone, PartialEq, Show)] #[deriving(Clone, PartialEq, Show)]

View File

@ -112,7 +112,7 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option<Hint>)
// permission without help of apk // permission without help of apk
#[cfg(all(test, not(target_os = "android")))] #[cfg(all(test, not(target_os = "android")))]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use super::*; use super::*;
use io::net::ip::*; use io::net::ip::*;

View File

@ -544,7 +544,7 @@ impl<'a> ToSocketAddr for &'a str {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use super::*; use super::*;
use str::FromStr; use str::FromStr;

View File

@ -20,14 +20,14 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use prelude::*; use prelude::v1::*;
use c_str::ToCStr;
use io::{Listener, Acceptor, IoResult, TimedOut, standard_error}; use io::{Listener, Acceptor, IoResult, TimedOut, standard_error};
use time::Duration;
use sys::pipe::UnixStream as UnixStreamImp;
use sys::pipe::UnixListener as UnixListenerImp;
use sys::pipe::UnixAcceptor as UnixAcceptorImp; use sys::pipe::UnixAcceptor as UnixAcceptorImp;
use sys::pipe::UnixListener as UnixListenerImp;
use sys::pipe::UnixStream as UnixStreamImp;
use time::Duration;
use sys_common; use sys_common;
@ -264,13 +264,17 @@ impl sys_common::AsInner<UnixAcceptorImp> for UnixAcceptor {
} }
#[cfg(test)] #[cfg(test)]
#[allow(experimental)]
mod tests { mod tests {
use super::*; use prelude::v1::*;
use io::*;
use io::test::*; use comm::channel;
use prelude::{Ok, Err, spawn, range, drop, Some, None, channel, Send, FnOnce, Clone};
use io::fs::PathExtensions; use io::fs::PathExtensions;
use io::{EndOfFile, TimedOut, ShortWrite, IoError, ConnectionReset};
use io::{NotConnected, BrokenPipe, OtherIoError, FileNotFound, InvalidInput};
use io::{PermissionDenied, Acceptor, Listener};
use io::test::*;
use super::*;
use thread::Thread;
use time::Duration; use time::Duration;
pub fn smalltest<F,G>(server: F, client: G) pub fn smalltest<F,G>(server: F, client: G)
@ -282,7 +286,7 @@ mod tests {
let mut acceptor = UnixListener::bind(&path1).listen(); let mut acceptor = UnixListener::bind(&path1).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
match UnixStream::connect(&path2) { match UnixStream::connect(&path2) {
Ok(c) => client(c), Ok(c) => client(c),
Err(e) => panic!("failed connect: {}", e), Err(e) => panic!("failed connect: {}", e),
@ -377,7 +381,7 @@ mod tests {
Err(e) => panic!("failed listen: {}", e), Err(e) => panic!("failed listen: {}", e),
}; };
spawn(move|| { let _t = Thread::spawn(move|| {
for _ in range(0u, times) { for _ in range(0u, times) {
let mut stream = UnixStream::connect(&path2); let mut stream = UnixStream::connect(&path2);
match stream.write(&[100]) { match stream.write(&[100]) {
@ -411,7 +415,7 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen(); let mut acceptor = UnixListener::bind(&addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr); let mut s = UnixStream::connect(&addr);
let mut buf = [0, 0]; let mut buf = [0, 0];
debug!("client reading"); debug!("client reading");
@ -427,7 +431,7 @@ mod tests {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
rx1.recv(); rx1.recv();
debug!("writer writing"); debug!("writer writing");
@ -450,7 +454,7 @@ mod tests {
let (tx1, rx) = channel(); let (tx1, rx) = channel();
let tx2 = tx1.clone(); let tx2 = tx1.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr); let mut s = UnixStream::connect(&addr);
s.write(&[1]).unwrap(); s.write(&[1]).unwrap();
rx.recv(); rx.recv();
@ -462,7 +466,7 @@ mod tests {
let s2 = s1.clone(); let s2 = s1.clone();
let (done, rx) = channel(); let (done, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
let mut buf = [0, 0]; let mut buf = [0, 0];
s2.read(&mut buf).unwrap(); s2.read(&mut buf).unwrap();
@ -481,7 +485,7 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen(); let mut acceptor = UnixListener::bind(&addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr); let mut s = UnixStream::connect(&addr);
let buf = &mut [0, 1]; let buf = &mut [0, 1];
s.read(buf).unwrap(); s.read(buf).unwrap();
@ -492,7 +496,7 @@ mod tests {
let s2 = s1.clone(); let s2 = s1.clone();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
s2.write(&[1]).unwrap(); s2.write(&[1]).unwrap();
tx.send(()); tx.send(());
@ -539,7 +543,7 @@ mod tests {
// continue to receive any pending connections. // continue to receive any pending connections.
let (tx, rx) = channel(); let (tx, rx) = channel();
let addr2 = addr.clone(); let addr2 = addr.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
tx.send(UnixStream::connect(&addr2).unwrap()); tx.send(UnixStream::connect(&addr2).unwrap());
}); });
let l = rx.recv(); let l = rx.recv();
@ -557,7 +561,7 @@ mod tests {
// Unset the timeout and make sure that this always blocks. // Unset the timeout and make sure that this always blocks.
a.set_timeout(None); a.set_timeout(None);
let addr2 = addr.clone(); let addr2 = addr.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
drop(UnixStream::connect(&addr2).unwrap()); drop(UnixStream::connect(&addr2).unwrap());
}); });
a.accept().unwrap(); a.accept().unwrap();
@ -595,11 +599,11 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap(); let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>(); let (_tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut a = a; let mut a = a;
let _s = a.accept().unwrap(); let _s = a.accept().unwrap();
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut b = [0]; let mut b = [0];
let mut s = UnixStream::connect(&addr).unwrap(); let mut s = UnixStream::connect(&addr).unwrap();
@ -632,16 +636,16 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap(); let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>(); let (_tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut a = a; let mut a = a;
let _s = a.accept().unwrap(); let _s = a.accept().unwrap();
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = UnixStream::connect(&addr).unwrap(); let mut s = UnixStream::connect(&addr).unwrap();
let s2 = s.clone(); let s2 = s.clone();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err()); assert!(s2.read(&mut [0]).is_err());
tx.send(()); tx.send(());
@ -658,12 +662,12 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap(); let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap(); let mut s = UnixStream::connect(&addr).unwrap();
rx.recv(); rx.recv();
assert!(s.write(&[0]).is_ok()); assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
s.set_timeout(Some(20)); s.set_timeout(Some(20));
@ -696,7 +700,7 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap(); let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap(); let mut s = UnixStream::connect(&addr).unwrap();
rx.recv(); rx.recv();
let mut amt = 0; let mut amt = 0;
@ -707,7 +711,7 @@ mod tests {
} }
} }
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
s.set_read_timeout(Some(20)); s.set_read_timeout(Some(20));
@ -725,12 +729,12 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap(); let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap(); let mut s = UnixStream::connect(&addr).unwrap();
rx.recv(); rx.recv();
assert!(s.write(&[0]).is_ok()); assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
s.set_write_timeout(Some(20)); s.set_write_timeout(Some(20));
@ -752,17 +756,17 @@ mod tests {
let addr = next_test_unix(); let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap(); let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap(); let mut s = UnixStream::connect(&addr).unwrap();
rx.recv(); rx.recv();
assert!(s.write(&[0]).is_ok()); assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
let s2 = s.clone(); let s2 = s.clone();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
assert!(s2.read(&mut [0]).is_ok()); assert!(s2.read(&mut [0]).is_ok());
tx2.send(()); tx2.send(());
@ -784,10 +788,10 @@ mod tests {
let mut a2 = a.clone(); let mut a2 = a.clone();
let addr2 = addr.clone(); let addr2 = addr.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr2); let _ = UnixStream::connect(&addr2);
}); });
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr); let _ = UnixStream::connect(&addr);
}); });
@ -807,14 +811,14 @@ mod tests {
let (tx, rx) = channel(); let (tx, rx) = channel();
let tx2 = tx.clone(); let tx2 = tx.clone();
spawn(move|| { let mut a = a; tx.send(a.accept()) }); let _t = Thread::spawn(move|| { let mut a = a; tx.send(a.accept()) });
spawn(move|| { let mut a = a2; tx2.send(a.accept()) }); let _t = Thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
let addr2 = addr.clone(); let addr2 = addr.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr2); let _ = UnixStream::connect(&addr2);
}); });
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr); let _ = UnixStream::connect(&addr);
}); });
@ -840,7 +844,7 @@ mod tests {
let mut a2 = a.clone(); let mut a2 = a.clone();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut a = a; let mut a = a;
tx.send(a.accept()); tx.send(a.accept());
}); });

View File

@ -141,7 +141,7 @@ impl TcpStream {
/// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap(); /// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();
/// let stream2 = stream.clone(); /// let stream2 = stream.clone();
/// ///
/// Thread::spawn(move|| { /// let _t = Thread::spawn(move|| {
/// // close this stream after one second /// // close this stream after one second
/// timer::sleep(Duration::seconds(1)); /// timer::sleep(Duration::seconds(1));
/// let mut stream = stream2; /// let mut stream = stream2;
@ -282,10 +282,10 @@ impl sys_common::AsInner<TcpStreamImp> for TcpStream {
/// use std::io::{Acceptor, Listener}; /// use std::io::{Acceptor, Listener};
/// use std::thread::Thread; /// use std::thread::Thread;
/// ///
/// let listener = TcpListener::bind("127.0.0.1:80"); /// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
/// ///
/// // bind the listener to the specified address /// // bind the listener to the specified address
/// let mut acceptor = listener.listen(); /// let mut acceptor = listener.listen().unwrap();
/// ///
/// fn handle_client(mut stream: TcpStream) { /// fn handle_client(mut stream: TcpStream) {
/// // ... /// // ...
@ -423,7 +423,7 @@ impl TcpAcceptor {
/// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap(); /// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap();
/// let a2 = a.clone(); /// let a2 = a.clone();
/// ///
/// Thread::spawn(move|| { /// let _t = Thread::spawn(move|| {
/// let mut a2 = a2; /// let mut a2 = a2;
/// for socket in a2.incoming() { /// for socket in a2.incoming() {
/// match socket { /// match socket {
@ -482,14 +482,16 @@ impl sys_common::AsInner<TcpAcceptorImp> for TcpAcceptor {
#[cfg(test)] #[cfg(test)]
#[allow(experimental)] #[allow(experimental)]
mod test { mod test {
use prelude::v1::*;
use comm::channel;
use thread::Thread;
use io::net::tcp::*; use io::net::tcp::*;
use io::net::ip::*; use io::net::ip::*;
use io::{EndOfFile, TimedOut, IoError, ShortWrite, OtherIoError, ConnectionAborted}; use io::{EndOfFile, TimedOut, IoError, ShortWrite, OtherIoError, ConnectionAborted};
use io::{ConnectionRefused, ConnectionReset, BrokenPipe, NotConnected}; use io::{ConnectionRefused, ConnectionReset, BrokenPipe, NotConnected};
use io::{PermissionDenied, Listener, Acceptor}; use io::{PermissionDenied, Listener, Acceptor};
use io::test::*; use io::test::*;
use prelude::{Ok, Err, spawn, range, drop, Some, None, channel, Clone};
use prelude::{Reader, Writer, IteratorExt};
// FIXME #11530 this fails on android because tests are run as root // FIXME #11530 this fails on android because tests are run as root
#[cfg_attr(any(windows, target_os = "android"), ignore)] #[cfg_attr(any(windows, target_os = "android"), ignore)]
@ -515,7 +517,7 @@ mod test {
let listener = TcpListener::bind(socket_addr); let listener = TcpListener::bind(socket_addr);
let mut acceptor = listener.listen(); let mut acceptor = listener.listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(("localhost", socket_addr.port)); let mut stream = TcpStream::connect(("localhost", socket_addr.port));
stream.write(&[144]).unwrap(); stream.write(&[144]).unwrap();
}); });
@ -531,7 +533,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(("localhost", addr.port)); let mut stream = TcpStream::connect(("localhost", addr.port));
stream.write(&[64]).unwrap(); stream.write(&[64]).unwrap();
}); });
@ -547,7 +549,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(("127.0.0.1", addr.port)); let mut stream = TcpStream::connect(("127.0.0.1", addr.port));
stream.write(&[44]).unwrap(); stream.write(&[44]).unwrap();
}); });
@ -563,7 +565,7 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(("::1", addr.port)); let mut stream = TcpStream::connect(("::1", addr.port));
stream.write(&[66]).unwrap(); stream.write(&[66]).unwrap();
}); });
@ -579,7 +581,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap(); stream.write(&[99]).unwrap();
}); });
@ -595,7 +597,7 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap(); stream.write(&[99]).unwrap();
}); });
@ -611,7 +613,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr); let _stream = TcpStream::connect(addr);
// Close // Close
}); });
@ -627,7 +629,7 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr); let _stream = TcpStream::connect(addr);
// Close // Close
}); });
@ -643,7 +645,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr); let _stream = TcpStream::connect(addr);
// Close // Close
}); });
@ -667,7 +669,7 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr); let _stream = TcpStream::connect(addr);
// Close // Close
}); });
@ -692,7 +694,7 @@ mod test {
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
drop(TcpStream::connect(addr)); drop(TcpStream::connect(addr));
tx.send(()); tx.send(());
}); });
@ -717,7 +719,7 @@ mod test {
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
drop(TcpStream::connect(addr)); drop(TcpStream::connect(addr));
tx.send(()); tx.send(());
}); });
@ -742,7 +744,7 @@ mod test {
let max = 10u; let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
for _ in range(0, max) { for _ in range(0, max) {
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap(); stream.write(&[99]).unwrap();
@ -762,7 +764,7 @@ mod test {
let max = 10u; let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
for _ in range(0, max) { for _ in range(0, max) {
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap(); stream.write(&[99]).unwrap();
@ -782,11 +784,11 @@ mod test {
static MAX: int = 10; static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen(); let acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut acceptor = acceptor; let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection // Start another task to handle the connection
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = stream; let mut stream = stream;
let mut buf = [0]; let mut buf = [0];
stream.read(&mut buf).unwrap(); stream.read(&mut buf).unwrap();
@ -801,7 +803,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) { fn connect(i: int, addr: SocketAddr) {
if i == MAX { return } if i == MAX { return }
spawn(move|| { let _t = Thread::spawn(move|| {
debug!("connecting"); debug!("connecting");
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
// Connect again before writing // Connect again before writing
@ -818,11 +820,11 @@ mod test {
static MAX: int = 10; static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen(); let acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut acceptor = acceptor; let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection // Start another task to handle the connection
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = stream; let mut stream = stream;
let mut buf = [0]; let mut buf = [0];
stream.read(&mut buf).unwrap(); stream.read(&mut buf).unwrap();
@ -837,7 +839,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) { fn connect(i: int, addr: SocketAddr) {
if i == MAX { return } if i == MAX { return }
spawn(move|| { let _t = Thread::spawn(move|| {
debug!("connecting"); debug!("connecting");
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
// Connect again before writing // Connect again before writing
@ -854,11 +856,11 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let acceptor = TcpListener::bind(addr).listen(); let acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut acceptor = acceptor; let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) { for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection // Start another task to handle the connection
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = stream; let mut stream = stream;
let mut buf = [0]; let mut buf = [0];
stream.read(&mut buf).unwrap(); stream.read(&mut buf).unwrap();
@ -873,7 +875,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) { fn connect(i: int, addr: SocketAddr) {
if i == MAX { return } if i == MAX { return }
spawn(move|| { let _t = Thread::spawn(move|| {
debug!("connecting"); debug!("connecting");
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
// Connect again before writing // Connect again before writing
@ -890,11 +892,11 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let acceptor = TcpListener::bind(addr).listen(); let acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut acceptor = acceptor; let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) { for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection // Start another task to handle the connection
spawn(move|| { let _t = Thread::spawn(move|| {
let mut stream = stream; let mut stream = stream;
let mut buf = [0]; let mut buf = [0];
stream.read(&mut buf).unwrap(); stream.read(&mut buf).unwrap();
@ -909,7 +911,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) { fn connect(i: int, addr: SocketAddr) {
if i == MAX { return } if i == MAX { return }
spawn(move|| { let _t = Thread::spawn(move|| {
debug!("connecting"); debug!("connecting");
let mut stream = TcpStream::connect(addr); let mut stream = TcpStream::connect(addr);
// Connect again before writing // Connect again before writing
@ -932,7 +934,7 @@ mod test {
pub fn peer_name(addr: SocketAddr) { pub fn peer_name(addr: SocketAddr) {
let acceptor = TcpListener::bind(addr).listen(); let acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut acceptor = acceptor; let mut acceptor = acceptor;
acceptor.accept().unwrap(); acceptor.accept().unwrap();
}); });
@ -967,7 +969,7 @@ mod test {
fn partial_read() { fn partial_read() {
let addr = next_test_ip4(); let addr = next_test_ip4();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut srv = TcpListener::bind(addr).listen().unwrap(); let mut srv = TcpListener::bind(addr).listen().unwrap();
tx.send(()); tx.send(());
let mut cl = srv.accept().unwrap(); let mut cl = srv.accept().unwrap();
@ -1004,7 +1006,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
rx.recv(); rx.recv();
let _stream = TcpStream::connect(addr).unwrap(); let _stream = TcpStream::connect(addr).unwrap();
// Close // Close
@ -1029,7 +1031,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s = TcpStream::connect(addr); let mut s = TcpStream::connect(addr);
let mut buf = [0, 0]; let mut buf = [0, 0];
assert_eq!(s.read(&mut buf), Ok(1)); assert_eq!(s.read(&mut buf), Ok(1));
@ -1042,7 +1044,7 @@ mod test {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
rx1.recv(); rx1.recv();
s2.write(&[1]).unwrap(); s2.write(&[1]).unwrap();
@ -1061,7 +1063,7 @@ mod test {
let (tx1, rx) = channel(); let (tx1, rx) = channel();
let tx2 = tx1.clone(); let tx2 = tx1.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s = TcpStream::connect(addr); let mut s = TcpStream::connect(addr);
s.write(&[1]).unwrap(); s.write(&[1]).unwrap();
rx.recv(); rx.recv();
@ -1073,7 +1075,7 @@ mod test {
let s2 = s1.clone(); let s2 = s1.clone();
let (done, rx) = channel(); let (done, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
let mut buf = [0, 0]; let mut buf = [0, 0];
s2.read(&mut buf).unwrap(); s2.read(&mut buf).unwrap();
@ -1092,7 +1094,7 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen(); let mut acceptor = TcpListener::bind(addr).listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s = TcpStream::connect(addr); let mut s = TcpStream::connect(addr);
let mut buf = [0, 1]; let mut buf = [0, 1];
s.read(&mut buf).unwrap(); s.read(&mut buf).unwrap();
@ -1103,7 +1105,7 @@ mod test {
let s2 = s1.clone(); let s2 = s1.clone();
let (done, rx) = channel(); let (done, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
s2.write(&[1]).unwrap(); s2.write(&[1]).unwrap();
done.send(()); done.send(());
@ -1117,7 +1119,7 @@ mod test {
fn shutdown_smoke() { fn shutdown_smoke() {
let addr = next_test_ip4(); let addr = next_test_ip4();
let a = TcpListener::bind(addr).unwrap().listen(); let a = TcpListener::bind(addr).unwrap().listen();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut a = a; let mut a = a;
let mut c = a.accept().unwrap(); let mut c = a.accept().unwrap();
assert_eq!(c.read_to_end(), Ok(vec!())); assert_eq!(c.read_to_end(), Ok(vec!()));
@ -1151,7 +1153,7 @@ mod test {
// flakiness. // flakiness.
if !cfg!(target_os = "freebsd") { if !cfg!(target_os = "freebsd") {
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
tx.send(TcpStream::connect(addr).unwrap()); tx.send(TcpStream::connect(addr).unwrap());
}); });
let _l = rx.recv(); let _l = rx.recv();
@ -1168,7 +1170,7 @@ mod test {
// Unset the timeout and make sure that this always blocks. // Unset the timeout and make sure that this always blocks.
a.set_timeout(None); a.set_timeout(None);
spawn(move|| { let _t = Thread::spawn(move|| {
drop(TcpStream::connect(addr).unwrap()); drop(TcpStream::connect(addr).unwrap());
}); });
a.accept().unwrap(); a.accept().unwrap();
@ -1179,11 +1181,11 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap(); let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>(); let (_tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut a = a; let mut a = a;
let _s = a.accept().unwrap(); let _s = a.accept().unwrap();
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut b = [0]; let mut b = [0];
let mut s = TcpStream::connect(addr).unwrap(); let mut s = TcpStream::connect(addr).unwrap();
@ -1216,16 +1218,16 @@ mod test {
let addr = next_test_ip4(); let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap(); let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>(); let (_tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut a = a; let mut a = a;
let _s = a.accept().unwrap(); let _s = a.accept().unwrap();
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = TcpStream::connect(addr).unwrap(); let mut s = TcpStream::connect(addr).unwrap();
let s2 = s.clone(); let s2 = s.clone();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err()); assert!(s2.read(&mut [0]).is_err());
tx.send(()); tx.send(());
@ -1242,12 +1244,12 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap(); let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap(); let mut s = TcpStream::connect(addr).unwrap();
rx.recv(); rx.recv();
assert!(s.write(&[0]).is_ok()); assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
s.set_timeout(Some(20)); s.set_timeout(Some(20));
@ -1275,7 +1277,7 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap(); let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap(); let mut s = TcpStream::connect(addr).unwrap();
rx.recv(); rx.recv();
let mut amt = 0; let mut amt = 0;
@ -1286,7 +1288,7 @@ mod test {
} }
} }
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
s.set_read_timeout(Some(20)); s.set_read_timeout(Some(20));
@ -1304,12 +1306,12 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap(); let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap(); let mut s = TcpStream::connect(addr).unwrap();
rx.recv(); rx.recv();
assert!(s.write(&[0]).is_ok()); assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
s.set_write_timeout(Some(20)); s.set_write_timeout(Some(20));
@ -1332,17 +1334,17 @@ mod test {
let addr = next_test_ip6(); let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap(); let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap(); let mut s = TcpStream::connect(addr).unwrap();
rx.recv(); rx.recv();
assert_eq!(s.write(&[0]), Ok(())); assert_eq!(s.write(&[0]), Ok(()));
let _ = rx.recv_opt(); let _ = rx.recv_opt();
}); }).detach();
let mut s = a.accept().unwrap(); let mut s = a.accept().unwrap();
let s2 = s.clone(); let s2 = s.clone();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut s2 = s2; let mut s2 = s2;
assert_eq!(s2.read(&mut [0]), Ok(1)); assert_eq!(s2.read(&mut [0]), Ok(1));
tx2.send(()); tx2.send(());
@ -1365,7 +1367,7 @@ mod test {
let (tx, rx) = channel(); let (tx, rx) = channel();
let (txdone, rxdone) = channel(); let (txdone, rxdone) = channel();
let txdone2 = txdone.clone(); let txdone2 = txdone.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut tcp = TcpStream::connect(addr).unwrap(); let mut tcp = TcpStream::connect(addr).unwrap();
rx.recv(); rx.recv();
tcp.write_u8(0).unwrap(); tcp.write_u8(0).unwrap();
@ -1376,7 +1378,7 @@ mod test {
let tcp = accept.accept().unwrap(); let tcp = accept.accept().unwrap();
let tcp2 = tcp.clone(); let tcp2 = tcp.clone();
let txdone3 = txdone.clone(); let txdone3 = txdone.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut tcp2 = tcp2; let mut tcp2 = tcp2;
tcp2.read_u8().unwrap(); tcp2.read_u8().unwrap();
txdone3.send(()); txdone3.send(());
@ -1402,10 +1404,10 @@ mod test {
let mut a = l.listen().unwrap(); let mut a = l.listen().unwrap();
let mut a2 = a.clone(); let mut a2 = a.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = TcpStream::connect(addr); let _ = TcpStream::connect(addr);
}); });
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = TcpStream::connect(addr); let _ = TcpStream::connect(addr);
}); });
@ -1423,13 +1425,13 @@ mod test {
let (tx, rx) = channel(); let (tx, rx) = channel();
let tx2 = tx.clone(); let tx2 = tx.clone();
spawn(move|| { let mut a = a; tx.send(a.accept()) }); let _t = Thread::spawn(move|| { let mut a = a; tx.send(a.accept()) });
spawn(move|| { let mut a = a2; tx2.send(a.accept()) }); let _t = Thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = TcpStream::connect(addr); let _ = TcpStream::connect(addr);
}); });
spawn(move|| { let _t = Thread::spawn(move|| {
let _ = TcpStream::connect(addr); let _ = TcpStream::connect(addr);
}); });
@ -1455,7 +1457,7 @@ mod test {
let mut a2 = a.clone(); let mut a2 = a.clone();
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut a = a; let mut a = a;
tx.send(a.accept()); tx.send(a.accept());
}); });

View File

@ -248,11 +248,14 @@ impl Writer for UdpStream {
#[cfg(test)] #[cfg(test)]
#[allow(experimental)] #[allow(experimental)]
mod test { mod test {
use super::*; use prelude::v1::*;
use comm::channel;
use io::net::ip::*; use io::net::ip::*;
use io::{ShortWrite, IoError, TimedOut, PermissionDenied}; use io::{IoError, ShortWrite, TimedOut, PermissionDenied};
use io::test::*; use io::test::*;
use prelude::{Ok, Err, spawn, range, drop, Some, None, channel, Clone, Reader, Writer}; use super::*;
use thread::Thread;
// FIXME #11530 this fails on android because tests are run as root // FIXME #11530 this fails on android because tests are run as root
#[cfg_attr(any(windows, target_os = "android"), ignore)] #[cfg_attr(any(windows, target_os = "android"), ignore)]
@ -272,7 +275,7 @@ mod test {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
match UdpSocket::bind(client_ip) { match UdpSocket::bind(client_ip) {
Ok(ref mut client) => { Ok(ref mut client) => {
rx1.recv(); rx1.recv();
@ -307,7 +310,7 @@ mod test {
let client_ip = next_test_ip6(); let client_ip = next_test_ip6();
let (tx, rx) = channel::<()>(); let (tx, rx) = channel::<()>();
spawn(move|| { let _t = Thread::spawn(move|| {
match UdpSocket::bind(client_ip) { match UdpSocket::bind(client_ip) {
Ok(ref mut client) => { Ok(ref mut client) => {
rx.recv(); rx.recv();
@ -343,8 +346,8 @@ mod test {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let send_as = |&: ip, val: &[u8]| { let send_as = |&:ip, val: &[u8]| {
match UdpSocket::bind(ip) { match UdpSocket::bind(ip) {
Ok(client) => { Ok(client) => {
let client = box client; let client = box client;
@ -387,7 +390,7 @@ mod test {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
match UdpSocket::bind(client_ip) { match UdpSocket::bind(client_ip) {
Ok(client) => { Ok(client) => {
let client = box client; let client = box client;
@ -449,7 +452,7 @@ mod test {
let mut sock1 = UdpSocket::bind(addr1).unwrap(); let mut sock1 = UdpSocket::bind(addr1).unwrap();
let sock2 = UdpSocket::bind(addr2).unwrap(); let sock2 = UdpSocket::bind(addr2).unwrap();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut sock2 = sock2; let mut sock2 = sock2;
let mut buf = [0, 0]; let mut buf = [0, 0];
assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1))); assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1)));
@ -461,7 +464,7 @@ mod test {
let (tx1, rx1) = channel(); let (tx1, rx1) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut sock3 = sock3; let mut sock3 = sock3;
rx1.recv(); rx1.recv();
sock3.send_to(&[1], addr2).unwrap(); sock3.send_to(&[1], addr2).unwrap();
@ -482,7 +485,7 @@ mod test {
let (tx1, rx) = channel(); let (tx1, rx) = channel();
let tx2 = tx1.clone(); let tx2 = tx1.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut sock2 = sock2; let mut sock2 = sock2;
sock2.send_to(&[1], addr1).unwrap(); sock2.send_to(&[1], addr1).unwrap();
rx.recv(); rx.recv();
@ -493,7 +496,7 @@ mod test {
let sock3 = sock1.clone(); let sock3 = sock1.clone();
let (done, rx) = channel(); let (done, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut sock3 = sock3; let mut sock3 = sock3;
let mut buf = [0, 0]; let mut buf = [0, 0];
sock3.recv_from(&mut buf).unwrap(); sock3.recv_from(&mut buf).unwrap();
@ -517,7 +520,7 @@ mod test {
let (tx, rx) = channel(); let (tx, rx) = channel();
let (serv_tx, serv_rx) = channel(); let (serv_tx, serv_rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut sock2 = sock2; let mut sock2 = sock2;
let mut buf = [0, 1]; let mut buf = [0, 1];
@ -533,7 +536,7 @@ mod test {
let (done, rx) = channel(); let (done, rx) = channel();
let tx2 = tx.clone(); let tx2 = tx.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut sock3 = sock3; let mut sock3 = sock3;
match sock3.send_to(&[1], addr2) { match sock3.send_to(&[1], addr2) {
Ok(..) => { let _ = tx2.send_opt(()); } Ok(..) => { let _ = tx2.send_opt(()); }
@ -561,7 +564,7 @@ mod test {
let (tx, rx) = channel(); let (tx, rx) = channel();
let (tx2, rx2) = channel(); let (tx2, rx2) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut a = a2; let mut a = a2;
assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1))); assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1)));
assert_eq!(a.send_to(&[0], addr1), Ok(())); assert_eq!(a.send_to(&[0], addr1), Ok(()));

View File

@ -15,7 +15,7 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use prelude::*; use prelude::v1::*;
use io::IoResult; use io::IoResult;
use libc; use libc;
@ -112,7 +112,10 @@ impl Writer for PipeStream {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use comm::channel;
use thread::Thread;
#[test] #[test]
fn partial_read() { fn partial_read() {
@ -123,7 +126,7 @@ mod test {
let out = PipeStream::open(writer); let out = PipeStream::open(writer);
let mut input = PipeStream::open(reader); let mut input = PipeStream::open(reader);
let (tx, rx) = channel(); let (tx, rx) = channel();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut out = out; let mut out = out;
out.write(&[10]).unwrap(); out.write(&[10]).unwrap();
rx.recv(); // don't close the pipe until the other read has finished rx.recv(); // don't close the pipe until the other read has finished

View File

@ -16,25 +16,25 @@
pub use self::StdioContainer::*; pub use self::StdioContainer::*;
pub use self::ProcessExit::*; pub use self::ProcessExit::*;
use prelude::*; use prelude::v1::*;
use c_str::{CString, ToCStr};
use collections::HashMap;
use comm::{channel, Receiver};
use fmt; use fmt;
use os; use hash::Hash;
use io::pipe::{PipeStream, PipePair};
use io::{IoResult, IoError}; use io::{IoResult, IoError};
use io; use io;
use libc; use libc;
use c_str::CString; use os;
use collections::HashMap;
use hash::Hash;
#[cfg(windows)]
use std::hash::sip::SipState;
use io::pipe::{PipeStream, PipePair};
use path::BytesContainer; use path::BytesContainer;
use thread::Thread;
use sys;
use sys::fs::FileDesc; use sys::fs::FileDesc;
use sys::process::Process as ProcessImp; use sys::process::Process as ProcessImp;
use sys;
use thread::Thread;
#[cfg(windows)] use std::hash::sip::SipState;
/// Signal a process to exit, without forcibly killing it. Corresponds to /// Signal a process to exit, without forcibly killing it. Corresponds to
/// SIGTERM on unix platforms. /// SIGTERM on unix platforms.
@ -741,18 +741,17 @@ impl Drop for Process {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(unused_imports)] use prelude::v1::*;
use super::*; use comm::channel;
use io::fs::PathExtensions;
use io::timer::*; use io::timer::*;
use io::{Truncate, Write, TimedOut, timer, process, FileNotFound}; use io::{Truncate, Write, TimedOut, timer, process, FileNotFound};
use prelude::{Ok, Err, spawn, range, drop, Box, Some, None, Option, Vec, Buffer};
use prelude::{from_str, Path, String, channel, Reader, Writer, Clone, Slice};
use prelude::{SliceExt, Str, StrExt, AsSlice, ToString, GenericPath};
use io::fs::PathExtensions;
use time::Duration;
use str;
use rt::running_on_valgrind; use rt::running_on_valgrind;
use str;
use super::*;
use thread::Thread;
use time::Duration;
// FIXME(#10380) these tests should not all be ignored on android. // FIXME(#10380) these tests should not all be ignored on android.
@ -1156,14 +1155,14 @@ mod tests {
fn wait_timeout2() { fn wait_timeout2() {
let (tx, rx) = channel(); let (tx, rx) = channel();
let tx2 = tx.clone(); let tx2 = tx.clone();
spawn(move|| { let _t = Thread::spawn(move|| {
let mut p = sleeper(); let mut p = sleeper();
p.set_timeout(Some(10)); p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut); assert_eq!(p.wait().err().unwrap().kind, TimedOut);
p.signal_kill().unwrap(); p.signal_kill().unwrap();
tx.send(()); tx.send(());
}); });
spawn(move|| { let _t = Thread::spawn(move|| {
let mut p = sleeper(); let mut p = sleeper();
p.set_timeout(Some(10)); p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut); assert_eq!(p.wait().err().unwrap().kind, TimedOut);

View File

@ -78,7 +78,7 @@ impl<T, A: Acceptor<T>> Acceptor<T> for IoResult<A> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use super::super::mem::*; use super::super::mem::*;
use io; use io;

View File

@ -520,8 +520,11 @@ impl Writer for StdWriter {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use prelude::v1::*;
use super::*; use super::*;
use prelude::*; use comm::channel;
use thread::Thread;
#[test] #[test]
fn smoke() { fn smoke() {
@ -537,7 +540,7 @@ mod tests {
let (tx, rx) = channel(); let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
spawn(move|| { let _t = Thread::spawn(move|| {
set_stdout(box w); set_stdout(box w);
println!("hello!"); println!("hello!");
}); });
@ -550,7 +553,7 @@ mod tests {
let (tx, rx) = channel(); let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
spawn(move|| { let _t = Thread::spawn(move || -> () {
set_stderr(box w); set_stderr(box w);
panic!("my special message"); panic!("my special message");
}); });

View File

@ -12,9 +12,10 @@
#![macro_escape] #![macro_escape]
use prelude::v1::*;
use libc; use libc;
use os; use os;
use prelude::*;
use std::io::net::ip::*; use std::io::net::ip::*;
use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed}; use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};

View File

@ -225,9 +225,10 @@ fn in_ms_u64(d: Duration) -> u64 {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::v1::*;
use super::Timer; use super::Timer;
use thread::Thread;
use time::Duration; use time::Duration;
#[test] #[test]
@ -357,9 +358,9 @@ mod test {
let mut timer = Timer::new().unwrap(); let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000)); let timer_rx = timer.periodic(Duration::milliseconds(1000));
spawn(move|| { Thread::spawn(move|| {
let _ = timer_rx.recv_opt(); let _ = timer_rx.recv_opt();
}); }).detach();
// when we drop the TimerWatcher we're going to destroy the channel, // when we drop the TimerWatcher we're going to destroy the channel,
// which must wake up the task on the other end // which must wake up the task on the other end
@ -371,9 +372,9 @@ mod test {
let mut timer = Timer::new().unwrap(); let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000)); let timer_rx = timer.periodic(Duration::milliseconds(1000));
spawn(move|| { Thread::spawn(move|| {
let _ = timer_rx.recv_opt(); let _ = timer_rx.recv_opt();
}); }).detach();
timer.oneshot(Duration::milliseconds(1)); timer.oneshot(Duration::milliseconds(1));
} }
@ -384,9 +385,9 @@ mod test {
let mut timer = Timer::new().unwrap(); let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000)); let timer_rx = timer.periodic(Duration::milliseconds(1000));
spawn(move|| { Thread::spawn(move|| {
let _ = timer_rx.recv_opt(); let _ = timer_rx.recv_opt();
}); }).detach();
timer.sleep(Duration::milliseconds(1)); timer.sleep(Duration::milliseconds(1));
} }

View File

@ -10,7 +10,7 @@
//! Utility implementations of Reader and Writer //! Utility implementations of Reader and Writer
use prelude::*; use prelude::v1::*;
use cmp; use cmp;
use io; use io;
use slice::bytes::MutableByteVector; use slice::bytes::MutableByteVector;
@ -278,11 +278,11 @@ impl<T: Iterator<u8>> Reader for IterReader<T> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::v1::*;
use io::{MemReader, ByRefReader}; use io::{MemReader, ByRefReader};
use io; use io;
use boxed::Box;
use super::*; use super::*;
use prelude::{Ok, range, Vec, Buffer, Writer, Reader, ToString, AsSlice};
#[test] #[test]
fn test_limit_reader_unlimited() { fn test_limit_reader_unlimited() {

View File

@ -265,6 +265,7 @@ mod std {
pub use cell; // used for tls! pub use cell; // used for tls!
pub use thread_local; // used for thread_local! pub use thread_local; // used for thread_local!
pub use kinds; // used for tls! pub use kinds; // used for tls!
pub use ops; // used for bitflags!
// The test runner calls ::std::os::args() but really wants realstd // The test runner calls ::std::os::args() but really wants realstd
#[cfg(test)] pub use realstd::os as os; #[cfg(test)] pub use realstd::os as os;

View File

@ -334,6 +334,7 @@ macro_rules! vec {
/// ///
/// ``` /// ```
/// use std::thread::Thread; /// use std::thread::Thread;
/// use std::comm::channel;
/// ///
/// let (tx1, rx1) = channel(); /// let (tx1, rx1) = channel();
/// let (tx2, rx2) = channel(); /// let (tx2, rx2) = channel();

Some files were not shown because too many files have changed in this diff Show More