use std::os;
use std::io;
use std::io::fs;
-use std::str::FromStr;
-use std::thunk::{Thunk};
+use std::str::{FromStr, from_str};
+use std::thunk::Thunk;
use getopts::{optopt, optflag, reqopt};
use common::Config;
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};
~~~no_run
extern crate libc;
+
+use std::c_str::ToCStr;
use std::ptr;
#[link(name = "readline")]
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:
```bash
time. Here's an example:
```{rust}
+# use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
fn main() {
let ordering = cmp(x, y); // ordering: Ordering
- if ordering == Less {
+ if ordering == Ordering::Less {
println!("less");
- } else if ordering == Greater {
+ } else if ordering == Ordering::Greater {
println!("greater");
- } else if ordering == Equal {
+ } else if ordering == Ordering::Equal {
println!("equal");
}
}
section on enums?
```{rust}
+# use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
fn main() {
let ordering = cmp(x, y);
- if ordering == Less {
+ if ordering == Ordering::Less {
println!("less");
- } else if ordering == Greater {
+ } else if ordering == Ordering::Greater {
println!("greater");
- } else if ordering == Equal {
+ } else if ordering == Ordering::Equal {
println!("equal");
}
}
We can re-write this as a `match`:
```{rust}
+# use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
fn main() {
let y = 10i;
match cmp(x, y) {
- Less => println!("less"),
- Greater => println!("greater"),
- Equal => println!("equal"),
+ Ordering::Less => println!("less"),
+ Ordering::Greater => println!("greater"),
+ Ordering::Equal => println!("equal"),
}
}
```
also implement the previous line like this:
```{rust}
+# use std::cmp::Ordering;
fn cmp(a: int, b: int) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
fn main() {
let y = 10i;
println!("{}", match cmp(x, y) {
- Less => "less",
- Greater => "greater",
- Equal => "equal",
+ Ordering::Less => "less",
+ Ordering::Greater => "greater",
+ Ordering::Equal => "equal",
});
}
```
```{rust,ignore}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", input);
match cmp(input, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => println!("You win!"),
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
}
}
fn cmp(a: int, b: int) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,ignore}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", input);
match cmp(input, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => println!("You win!"),
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
}
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,ignore}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", input_num);
match cmp(input_num, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => println!("You win!"),
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
}
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,no_run}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", num);
match cmp(num, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => println!("You win!"),
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
}
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,no_run}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", num);
match cmp(num, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => println!("You win!"),
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
}
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,no_run}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", num);
match cmp(num, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => println!("You win!"),
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
}
}
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,no_run}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", num);
match cmp(num, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => {
println!("You win!");
return;
},
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,no_run}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", num);
match cmp(num, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => {
println!("You win!");
return;
},
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
```{rust,no_run}
use std::io;
use std::rand;
+use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
println!("You guessed: {}", num);
match cmp(num, secret_number) {
- Less => println!("Too small!"),
- Greater => println!("Too big!"),
- Equal => {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => {
println!("You win!");
return;
},
}
fn cmp(a: uint, b: uint) -> Ordering {
- if a < b { Less }
- else if a > b { Greater }
- else { Equal }
+ if a < b { Ordering::Less }
+ else if a > b { Ordering::Greater }
+ else { Ordering::Equal }
}
```
hence 'statically dispatched'. The downside is that we have two copies of
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
broad subsection of software developers. Modern computers are often multi-core,
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
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
(recursive) unwinding of the stack of a failed destructor. Nonetheless, 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*
state, a panic occurring from within this destructor results in *hard* panic.
A hard panic currently results in the process aborting.
//! [dir_graph]: http://en.wikipedia.org/wiki/Directed_graph
//!
//! ```
+//! use std::cmp::Ordering;
//! use std::collections::BinaryHeap;
//! use std::uint;
//!
use core::prelude::*;
use core::default::Default;
+use core::iter::FromIterator;
use core::mem::{zeroed, replace, swap};
use core::ptr;
use core::prelude::*;
+use core::cmp::Ordering;
use core::cmp;
use core::default::Default;
use core::fmt;
+use core::hash;
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::slice;
+use core::ops::Index;
+use core::slice::{Iter, IterMut};
use core::{u8, u32, uint};
use bitv_set; //so meta
-use core::hash;
use Vec;
type Blocks<'a> = Cloned<slice::Iter<'a, u32>>;
#[cfg(test)]
mod bitv_bench {
- use std::prelude::*;
+ use std::prelude::v1::*;
use std::rand;
use std::rand::Rng;
use std::u32;
#[cfg(test)]
mod bitv_set_bench {
- use std::prelude::*;
+ use std::prelude::v1::*;
use std::rand;
use std::rand::Rng;
use std::u32;
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 std::hash::{Writer, Hash};
+use core::cmp::Ordering;
use core::default::Default;
-use core::{iter, fmt, mem};
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 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
use core::prelude::*;
use core::kinds::marker;
use core::mem;
+ use core::ops::{Deref, DerefMut};
use super::BTreeMap;
use super::super::node::{mod, Node, Fit, Split, Internal, Leaf};
use super::super::node::handle;
use core::prelude::*;
-use core::{slice, mem, ptr, cmp, num, raw};
-use core::iter::Zip;
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::{slice, mem, ptr, cmp, num, raw};
use alloc::heap;
/// Represents the result of an Insertion: either the item fit, or the node had to split
use core::prelude::*;
-use btree_map::{BTreeMap, Keys};
-use std::hash::Hash;
use core::borrow::BorrowFrom;
+use core::cmp::Ordering::{mod, Less, Greater, Equal};
use core::default::Default;
-use core::fmt;
-use core::iter::{Peekable, Map};
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
use core::prelude::*;
use alloc::boxed::Box;
+use core::cmp::Ordering;
use core::default::Default;
use core::fmt;
-use core::iter;
+use core::hash::{Writer, Hash};
+use core::iter::{mod, FromIterator};
use core::mem;
use core::ptr;
-use std::hash::{Writer, Hash};
/// A doubly-linked list.
#[stable]
use core::prelude::*;
use core::fmt;
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)
use core::prelude::*;
+use core::cmp::Ordering;
use core::default::Default;
use core::fmt;
-use core::iter;
-use core::raw::Slice as RawSlice;
-use core::ptr;
+use core::iter::{mod, FromIterator, RandomAccessIterator};
use core::kinds::marker;
use core::mem;
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::cmp;
use alloc::boxed::Box;
use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned};
-use core::cmp;
-use core::iter::{range_step, MultiplicativeIterator};
+use core::clone::Clone;
+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::mem::size_of;
use core::mem;
-use core::ops::{FnMut,SliceMut};
-use core::prelude::{Clone, Greater, Iterator, IteratorExt, Less, None, Option};
-use core::prelude::{Ord, Ordering, PtrExt, Some, range, IteratorCloneExt, Result};
+use core::ops::{FnMut, SliceMut};
+use core::option::Option::{mod, Some, None};
+use core::ptr::PtrExt;
use core::ptr;
+use core::result::Result;
use core::slice as core_slice;
use self::Direction::*;
use core::prelude::*;
use core::borrow::{Cow, IntoCow};
+use core::cmp::Equiv;
use core::default::Default;
use core::fmt;
use core::hash;
+use core::iter::FromIterator;
use core::mem;
+use core::ops::{mod, Deref, Add};
use core::ptr;
-use core::ops;
use core::raw::Slice as RawSlice;
use unicode::str as unicode_str;
use unicode::str::Utf16Item;
use alloc::heap::{EMPTY, allocate, reallocate, deallocate};
use core::borrow::{Cow, IntoCow};
use core::cmp::max;
+use core::cmp::{Equiv, Ordering};
use core::default::Default;
use core::fmt;
use core::hash::{mod, Hash};
-use core::iter::repeat;
+use core::iter::{repeat, FromIterator};
use core::kinds::marker::{ContravariantLifetime, InvariantType};
use core::mem;
use core::nonzero::NonZero;
use core::num::{Int, UnsignedInt};
+use core::ops::{Index, IndexMut, Deref, Add};
use core::ops;
use core::ptr;
use core::raw::Slice as RawSlice;
use core::prelude::*;
+use core::cmp::Ordering;
use core::default::Default;
use core::fmt;
use core::hash::{Hash, Writer};
+use core::iter::{Enumerate, FilterMap, Map, FromIterator};
use core::iter;
-use core::iter::{Enumerate, FilterMap, Map};
use core::mem::replace;
+use core::ops::{Index, IndexMut};
use {vec, slice};
use vec::Vec;
/// # Example
///
/// ```rust
+ /// use std::cmp::Ordering::{Less, Equal, Greater};
+ ///
/// assert_eq!(Less.reverse(), Greater);
/// assert_eq!(Equal.reverse(), Equal);
/// assert_eq!(Greater.reverse(), Less);
///
- ///
/// let mut data: &mut [_] = &mut [2u, 10, 5, 8];
///
/// // sort the array from largest to smallest.
/// 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!(10u.cmp(&5), Greater); // because 10 > 5
/// assert_eq!( 5u.cmp(&5), Equal); // because 5 == 5
//! demonstrates adding and subtracting two `Point`s.
//!
//! ```rust
+//! use std::ops::{Add, Sub};
+//!
//! #[deriving(Show)]
//! struct Point {
//! x: int,
/// struct HasDrop;
///
/// impl Drop for HasDrop {
-/// fn drop(&mut self) {
-/// println!("Dropping!");
-/// }
+/// fn drop(&mut self) {
+/// println!("Dropping!");
+/// }
/// }
///
/// fn main() {
-/// let _x = HasDrop;
+/// let _x = HasDrop;
/// }
/// ```
#[lang="drop"]
/// calling `add`, and therefore, `main` prints `Adding!`.
///
/// ```rust
+/// use std::ops::Add;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
///
/// ```rust
+/// use std::ops::Sub;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `mul`, and therefore, `main` prints `Multiplying!`.
///
/// ```rust
+/// use std::ops::Mul;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `div`, and therefore, `main` prints `Dividing!`.
///
/// ```
+/// use std::ops::Div;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `rem`, and therefore, `main` prints `Remainder-ing!`.
///
/// ```
+/// use std::ops::Rem;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// `neg`, and therefore, `main` prints `Negating!`.
///
/// ```
+/// use std::ops::Neg;
+///
/// struct Foo;
///
/// impl Copy for Foo {}
/// `not`, and therefore, `main` prints `Not-ing!`.
///
/// ```
+/// use std::ops::Not;
+///
/// struct Foo;
///
/// impl Copy for Foo {}
/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`.
///
/// ```
+/// use std::ops::BitAnd;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
///
/// ```
+/// use std::ops::BitOr;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
///
/// ```
+/// use std::ops::BitXor;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `shl`, and therefore, `main` prints `Shifting left!`.
///
/// ```
+/// use std::ops::Shl;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `shr`, and therefore, `main` prints `Shifting right!`.
///
/// ```
+/// use std::ops::Shr;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `index`, and therefore, `main` prints `Indexing!`.
///
/// ```
+/// use std::ops::Index;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `index_mut`, and therefore, `main` prints `Indexing!`.
///
/// ```
+/// use std::ops::IndexMut;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `slice_to`, and therefore, `main` prints `Slicing!`.
///
/// ```ignore
+/// use std::ops::Slice;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// calling `slice_from_mut`, and therefore, `main` prints `Slicing!`.
///
/// ```ignore
+/// use std::ops::SliceMut;
+///
/// #[deriving(Copy)]
/// struct Foo;
///
/// struct.
///
/// ```
+/// use std::ops::Deref;
+///
/// struct DerefExample<T> {
/// value: T
/// }
/// struct.
///
/// ```
+/// use std::ops::{Deref, DerefMut};
+///
/// struct DerefMutExample<T> {
/// value: T
/// }
// Reexported core operators
pub use kinds::{Copy, Send, Sized, Sync};
-pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
-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};
+pub use ops::{Drop, Fn, FnMut, FnOnce};
// Reexported functions
pub use iter::range;
pub use mem::drop;
-pub use str::from_str;
// Reexported types and traits
pub use char::Char;
pub use clone::Clone;
pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
-pub use cmp::{Ordering, Equiv};
-pub use cmp::Ordering::{Less, Equal, Greater};
-pub use iter::{FromIterator, Extend, IteratorExt};
-pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt, RandomAccessIterator};
-pub use iter::{IteratorCloneExt, CloneIteratorExt, IteratorPairExt};
-pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator, ExactSizeIterator};
-pub use num::{ToPrimitive, FromPrimitive};
-pub use option::Option;
-pub use option::Option::{Some, None};
+pub use iter::{Extend, IteratorExt};
+pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt};
+pub use iter::{IteratorCloneExt, CloneIteratorExt};
+pub use iter::{IteratorOrdExt, ExactSizeIterator, IteratorPairExt};
+pub use option::Option::{mod, Some, None};
pub use ptr::{PtrExt, MutPtrExt};
-pub use result::Result;
-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 result::Result::{mod, Ok, Err};
pub use slice::{AsSlice, SliceExt};
+pub use slice::{PartialEqSliceExt, OrdSliceExt};
+pub use str::{Str, StrExt};
//! * `PartialOrd`
//! * `Ord`
//! * `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]
// option. This file may not be copied, modified, or distributed
// 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]
fn test_int_totalord() {
use core::int;
use core::num::{FromStrRadix, Int, SignedInt};
use core::str::from_str;
+ use core::ops::{Shl, Shr, Not, BitXor, BitAnd, BitOr};
use num;
#[test]
use core::num::{NumCast, cast};
use core::ops::{Add, Sub, Mul, Div, Rem};
use core::kinds::Copy;
+use std::str::from_str;
mod int_macros;
mod i8;
use core::option::Option::{Some, None};
use core::num::Float;
use core::num::from_str_radix;
+ use core::str::from_str;
#[test]
fn from_str_issue7588() {
use core::$T_i::*;
use core::num::Int;
use num;
+ use core::ops::{BitOr, BitAnd, BitXor, Shl, Shr, Not};
#[test]
fn test_overflows() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::str::from_str;
+
#[test]
fn test_bool_from_str() {
assert_eq!(from_str::<bool>("true"), Some(true));
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::cmp::Ordering::{Equal, Less, Greater};
+
#[test]
fn test_clone() {
let a = (1i, "2");
//! which is cyclic.
//!
//! ```rust
+//! use std::borrow::IntoCow;
//! use graphviz as dot;
//!
//! type Nd = int;
//! entity `&sube`).
//!
//! ```rust
+//! use std::borrow::IntoCow;
//! use graphviz as dot;
//!
//! type Nd = uint;
//! Hasse-diagram for the subsets of the set `{x, y}`.
//!
//! ```rust
+//! use std::borrow::IntoCow;
//! use graphviz as dot;
//!
//! type Nd<'a> = (uint, &'a str);
pub use self::LabelText::*;
+use std::borrow::IntoCow;
use std::io;
use std::str::CowString;
use std::vec::CowVec;
use super::{Nodes, Edges, GraphWalk, render};
use std::io::IoResult;
use std::str;
+ use std::borrow::IntoCow;
/// each node is an index in a vector in the graph.
type Node = uint;
pub use self::MaybeOwnedVector::*;
+use std::cmp::{Equiv, Ordering};
use std::default::Default;
use std::fmt;
+use std::iter::FromIterator;
use std::path::BytesContainer;
use std::slice;
fn from_iter<I:Iterator<T>>(iterator: I) -> MaybeOwnedVector<'a,T> {
// If we are building from scratch, might as well build the
// most flexible variant.
- Growable(FromIterator::from_iter(iterator))
+ Growable(iterator.collect())
}
}
#[cfg(test)]
mod test {
- use std::prelude::*;
+ use std::prelude::v1::*;
use core::iter::order;
use {Rng, SeedableRng};
#[cfg(test)]
mod test {
- use std::prelude::*;
+ use std::prelude::v1::*;
use distributions::{Sample, IndependentSample};
use super::Exp;
mod bench {
extern crate test;
- use std::prelude::*;
+ use std::prelude::v1::*;
use self::test::Bencher;
use std::mem::size_of;
#[cfg(test)]
mod test {
- use std::prelude::*;
+ use std::prelude::v1::*;
use distributions::{Sample, IndependentSample};
use super::{ChiSquared, StudentT, FisherF};
#[cfg(test)]
mod bench {
extern crate test;
- use std::prelude::*;
+ use std::prelude::v1::*;
use self::test::Bencher;
use std::mem::size_of;
use distributions::IndependentSample;
#[cfg(test)]
mod tests {
- use std::prelude::*;
+ use std::prelude::v1::*;
use {Rng, Rand};
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};
#[cfg(test)]
mod tests {
- use std::prelude::*;
+ use std::prelude::v1::*;
use distributions::{Sample, IndependentSample};
use super::{Normal, LogNormal};
#[cfg(test)]
mod bench {
extern crate test;
- use std::prelude::*;
+ use std::prelude::v1::*;
use self::test::Bencher;
use std::mem::size_of;
use distributions::{Sample};
#[cfg(test)]
mod tests {
use std::num::Int;
- use std::prelude::*;
+ use std::prelude::v1::*;
use distributions::{Sample, IndependentSample};
use super::Range;
#[cfg(test)]
mod test {
- use std::prelude::*;
+ use std::prelude::v1::*;
use core::iter::order;
use {Rng, SeedableRng};
#[cfg(test)]
mod tests {
- use std::prelude::*;
+ use std::prelude::v1::*;
use std::rand::{Rng, thread_rng, Open01, Closed01};
struct ConstantRng(u64);
#[cfg(test)]
mod test {
- use std::prelude::*;
+ use std::prelude::v1::*;
use core::iter::order;
use super::{ReseedingRng, ReseedWithDefault};
pub use self::NamesIter::*;
pub use self::Regex::*;
+use std::borrow::IntoCow;
use std::collections::HashMap;
use std::fmt;
use std::str::CowString;
pub use self::StepState::*;
use std::cmp;
+use std::cmp::Ordering::{mod, Less, Equal, Greater};
use std::mem;
use std::iter::repeat;
use std::slice::SliceExt;
use util::nodemap::{FnvHashMap, NodeSet};
use lint::{Context, LintPass, LintArray};
-use std::{cmp, slice};
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::num::SignedInt;
+use std::{cmp, slice};
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
+
use syntax::{abi, ast, ast_map};
use syntax::ast_util::is_shift_binop;
use syntax::attr::{mod, AttrMetaMethods};
use middle::ty::{mod, Ty};
use middle::astencode::vtable_decoder_helpers;
+use std::collections::HashMap;
use std::hash::Hash;
use std::hash;
use std::io::extensions::u64_from_be_bytes;
use std::io;
-use std::collections::hash_map::HashMap;
+use std::num::FromPrimitive;
use std::rc::Rc;
use std::str;
+
use rbml::reader;
use rbml;
use serialize::Decodable;
use std::rc::Rc;
use std::str;
-use std::string::String;
use syntax::abi;
use syntax::ast;
use syntax::parse::token;
/// This module provides linkage between rustc::middle::graph and
/// 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 syntax::ast;
use middle::ty::*;
use middle::ty;
use std::fmt;
-use std::iter::AdditiveIterator;
-use std::iter::{range_inclusive, repeat};
+use std::iter::{range_inclusive, AdditiveIterator, FromIterator, repeat};
use std::num::Float;
use std::slice;
use syntax::ast::{mod, DUMMY_NODE_ID, NodeId, Pat};
use syntax::visit::{mod, Visitor};
use syntax::{ast_map, ast_util, codemap};
-use std::rc::Rc;
use std::collections::hash_map::Entry::Vacant;
+use std::rc::Rc;
//
// This pass classifies expressions by their constant-ness.
use util::ppaux::Repr;
use std::cell::{Cell, RefCell};
-use std::u32;
+use std::cmp::Ordering::{mod, Less, Greater, Equal};
use std::iter::repeat;
+use std::u32;
use syntax::ast;
mod doc;
use syntax::visit;
use std::iter::Enumerate;
+use std::num::FromPrimitive;
use std::slice;
// The actual lang items defined come at the end of this file in one handy table.
use arena::TypedArena;
use std::borrow::BorrowFrom;
use std::cell::{Cell, RefCell};
-use std::cmp;
+use std::cmp::{mod, Ordering};
use std::fmt::{mod, Show};
use std::hash::{Hash, sip, Writer};
use std::mem;
mod cgsetters {
use super::{CodegenOptions, Passes, SomePasses, AllPasses};
+ use std::str::from_str;
$(
pub fn $opt(cg: &mut CodegenOptions, v: Option<&str>) -> bool {
}
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())
}
}
use rustc::middle::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
use rustc::middle::dataflow;
use std::rc::Rc;
+use std::borrow::IntoCow;
#[deriving(Show, Copy)]
pub enum Variant {
use rustc::DIAGNOSTICS;
use std::any::AnyRefExt;
+use std::cmp::Ordering::Equal;
+use std::comm::channel;
use std::io;
use std::iter::repeat;
use std::os;
use libc;
use ArchiveRef;
-use std::raw;
+use std::c_str::ToCStr;
use std::mem;
+use std::raw;
pub struct ArchiveRO {
ptr: ArchiveRef,
use syntax::codemap::{Span, DUMMY_SP};
use syntax::visit::{mod, Visitor};
-use std::rc::Rc;
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
// another item exists with the same name in some namespace.
// `use` directives.
//
+use std::ops::{Deref, DerefMut};
+
use Resolver;
use Namespace::{TypeNS, ValueNS};
use syntax::ast;
use syntax::parse::token;
+use std::ops::{Deref, DerefMut};
use std::rc::Rc;
struct ExportRecorder<'a, 'b:'a, 'tcx:'b> {
use libc;
use flate;
+use std::c_str::ToCStr;
use std::iter;
use std::mem;
use std::num::Int;
use syntax::diagnostic::{Emitter, Handler, Level, mk_handler};
use std::c_str::{ToCStr, CString};
+use std::comm::channel;
use std::io::Command;
use std::io::fs;
use std::iter::Unfold;
let glob_map = &self.analysis.glob_map;
let glob_map = glob_map.as_ref().unwrap();
if glob_map.contains_key(&id) {
- let names = glob_map.index(&id);
- for n in names.iter() {
+ for n in glob_map[id].iter() {
if name_string.len() > 0 {
name_string.push_str(", ");
}
use trans::type_::Type;
use util::nodemap::FnvHashMap;
use libc::{c_uint, c_char};
-use std::string::String;
+use std::c_str::ToCStr;
use syntax::codemap::Span;
pub struct Builder<'a, 'tcx: 'a> {
use middle::ty::{mod, Ty};
use middle::subst::{Substs};
use std::cmp;
+use std::c_str::ToCStr;
use libc::c_uint;
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
use syntax::abi::{RustIntrinsic, Rust, RustCall, Stdcall, Fastcall, System};
pub use self::imp::Lock;
-
#[cfg(unix)]
mod imp {
use libc;
+ use std::c_str::ToCStr;
#[cfg(target_os = "linux")]
mod os {
use libc;
use std::ascii::AsciiExt;
+use std::c_str::ToCStr;
use std::cell::{RefCell, Cell};
+use std::collections::HashMap;
use std::fmt;
use std::slice;
use std::str;
-use std::collections::HashMap;
use html::toc::TocBuilder;
use html::highlight;
pub use self::ExternalLocation::*;
use std::cell::RefCell;
+use std::cmp::Ordering::{mod, Less, Greater, Equal};
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::{HashMap, HashSet};
use std::default::Default;
//! hierarchy, with item counts for every stability level per module. A parent
//! module's count includes its children's.
-use std::ops::Add;
+use std::cmp::Ordering;
use std::num::Zero;
+use std::ops::Add;
use syntax::attr::{Deprecated, Experimental, Unstable, Stable, Frozen, Locked};
use syntax::ast::Public;
// except according to those terms.
use std::cell::RefCell;
+use std::comm::channel;
use std::dynamic_lib::DynamicLibrary;
use std::io::{Command, TempDir};
use std::io;
use std::os;
use std::str;
-use std::string::String;
-use std::thunk::Thunk;
use std::thread::Thread;
+use std::thunk::Thunk;
use std::collections::{HashSet, HashMap};
use testing;
#[cfg(test)]
mod tests {
+ use prelude::v1::*;
use super::*;
- use prelude::*;
use char::from_u32;
#[test]
}
}
- impl BitOr<$BitFlags, $BitFlags> for $BitFlags {
+ impl ::std::ops::BitOr<$BitFlags, $BitFlags> for $BitFlags {
/// Returns the union of the two sets of flags.
#[inline]
fn bitor(self, other: $BitFlags) -> $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.
#[inline]
fn bitxor(self, other: $BitFlags) -> $BitFlags {
}
}
- impl BitAnd<$BitFlags, $BitFlags> for $BitFlags {
+ impl ::std::ops::BitAnd<$BitFlags, $BitFlags> for $BitFlags {
/// Returns the intersection between the two sets of flags.
#[inline]
fn bitand(self, other: $BitFlags) -> $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.
#[inline]
fn sub(self, other: $BitFlags) -> $BitFlags {
}
}
- impl Not<$BitFlags> for $BitFlags {
+ impl ::std::ops::Not<$BitFlags> for $BitFlags {
/// Returns the complement of this set of flags.
#[inline]
fn not(self) -> $BitFlags {
//! ```rust
//! extern crate libc;
//!
+//! use std::c_str::ToCStr;
+//!
//! extern {
//! fn puts(s: *const libc::c_char);
//! }
use core::prelude::*;
use libc;
+use cmp::Ordering;
use fmt;
use hash;
use mem;
/// one).
///
/// ```rust
+ /// use std::c_str::ToCStr;
+ ///
/// let foo = "some string";
///
/// // right
/// ```rust
/// extern crate libc;
///
+ /// use std::c_str::ToCStr;
+ ///
/// fn main() {
/// let c_str = "foo bar".to_c_str();
/// unsafe {
/// one).
///
/// ```rust
+ /// use std::c_str::ToCStr;
+ ///
/// let foo = "some string";
///
/// // right
/// ```rust
/// extern crate libc;
///
+ /// use std::c_str::ToCStr;
+ ///
/// fn main() {
/// let s = "PATH".with_c_str(|path| unsafe {
/// libc::getenv(path)
#[cfg(test)]
mod tests {
use super::*;
- use prelude::{spawn, Some, None, Option, FnOnce, ToString, CloneSliceExt};
- use prelude::{Clone, PtrExt, Iterator, SliceExt, StrExt};
+ use prelude::v1::*;
use ptr;
use thread::Thread;
use libc;
mod bench {
extern crate test;
+ use prelude::v1::*;
use self::test::Bencher;
use libc;
- use prelude::*;
+ use c_str::ToCStr;
#[inline]
fn check(s: &str, c_str: *const libc::c_char) {
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use super::CVec;
use libc;
#![cfg(test)]
extern crate test;
-use prelude::*;
+use prelude::v1::*;
use self::test::Bencher;
use iter::{range_inclusive};
#[test]
fn test_resize_policy() {
- use prelude::*;
+ use prelude::v1::*;
let rp = DefaultResizePolicy;
for n in range(0u, 1000) {
assert!(rp.min_capacity(rp.usable_capacity(n)) <= n);
#[cfg(test)]
mod test_map {
- use prelude::*;
+ use prelude::v1::*;
+ use cmp::Equiv;
use super::HashMap;
use super::Entry::{Occupied, Vacant};
use hash;
#[cfg(test)]
mod test_set {
- use prelude::*;
+ use prelude::v1::*;
use super::HashSet;
//!
//! ```
//! use std::thread::Thread;
+//! use std::comm::channel;
//!
//! // Create a simple streaming channel
//! let (tx, rx) = channel();
//!
//! ```
//! use std::thread::Thread;
+//! use std::comm::channel;
//!
//! // Create a shared channel that can be sent along from many threads
//! // where tx is the sending half (tx for transmission), and rx is the receiving
//! Propagating panics:
//!
//! ```should_fail
+//! use std::comm::channel;
+//!
//! // The call to recv() will panic!() because the channel has already hung
//! // up (or been deallocated)
//! let (tx, rx) = channel::<int>();
//!
//! ```
//! use std::thread::Thread;
+//! use std::comm::sync_channel;
//!
//! let (tx, rx) = sync_channel::<int>(0);
//! Thread::spawn(move|| {
//! after 10 seconds no matter what:
//!
//! ```no_run
+//! use std::comm::channel;
//! use std::io::timer::Timer;
//! use std::time::Duration;
//!
//! has been inactive for 5 seconds:
//!
//! ```no_run
+//! use std::comm::channel;
//! use std::io::timer::Timer;
//! use std::time::Duration;
//!
use self::select::StartResult::*;
use self::blocking::SignalToken;
-macro_rules! test {
- { fn $name:ident() $b:block $(#[$a:meta])*} => (
- mod $name {
- #![allow(unused_imports)]
-
- use super::*;
- use comm::*;
- use thread::Thread;
- use prelude::{Ok, Err, spawn, range, drop, Box, Some, None, Option};
- use prelude::{Vec, Buffer, from_str, Clone};
-
- $(#[$a])* #[test] fn f() { $b }
- }
- )
-}
-
mod blocking;
mod oneshot;
mod select;
/// # Example
///
/// ```
+/// use std::comm::channel;
/// use std::thread::Thread;
///
/// // tx is is the sending half (tx for transmission), and rx is the receiving
/// # Example
///
/// ```
+/// use std::comm::sync_channel;
/// use std::thread::Thread;
///
/// let (tx, rx) = sync_channel(1);
/// # Example
///
/// ```
+ /// use std::comm::channel;
+ ///
/// let (tx, rx) = channel();
///
/// // This send is always successful
#[cfg(test)]
mod test {
- use super::*;
- use prelude::{spawn, range, Some, None, from_str, Clone, Str};
+ use prelude::v1::*;
+
use os;
+ use super::*;
+ use thread::Thread;
+ use str::from_str;
pub fn stress_factor() -> uint {
match os::getenv("RUST_TEST_STRESS") {
}
}
- test! { fn smoke() {
+ #[test]
+ fn smoke() {
let (tx, rx) = channel::<int>();
tx.send(1);
assert_eq!(rx.recv(), 1);
- } }
+ }
- test! { fn drop_full() {
+ #[test]
+ fn drop_full() {
let (tx, _rx) = channel();
tx.send(box 1i);
- } }
+ }
- test! { fn drop_full_shared() {
+ #[test]
+ fn drop_full_shared() {
let (tx, _rx) = channel();
drop(tx.clone());
drop(tx.clone());
tx.send(box 1i);
- } }
+ }
- test! { fn smoke_shared() {
+ #[test]
+ fn smoke_shared() {
let (tx, rx) = channel::<int>();
tx.send(1);
assert_eq!(rx.recv(), 1);
let tx = tx.clone();
tx.send(1);
assert_eq!(rx.recv(), 1);
- } }
+ }
- test! { fn smoke_threads() {
+ #[test]
+ fn smoke_threads() {
let (tx, rx) = channel::<int>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
tx.send(1);
});
assert_eq!(rx.recv(), 1);
- } }
+ }
- test! { fn smoke_port_gone() {
+ #[test]
+ #[should_fail]
+ fn smoke_port_gone() {
let (tx, rx) = channel::<int>();
drop(rx);
tx.send(1);
- } #[should_fail] }
+ }
- test! { fn smoke_shared_port_gone() {
+ #[test]
+ #[should_fail]
+ fn smoke_shared_port_gone() {
let (tx, rx) = channel::<int>();
drop(rx);
tx.send(1);
- } #[should_fail] }
+ }
- test! { fn smoke_shared_port_gone2() {
+ #[test]
+ #[should_fail]
+ fn smoke_shared_port_gone2() {
let (tx, rx) = channel::<int>();
drop(rx);
let tx2 = tx.clone();
drop(tx);
tx2.send(1);
- } #[should_fail] }
+ }
- test! { fn port_gone_concurrent() {
+ #[test]
+ #[should_fail]
+ fn port_gone_concurrent() {
let (tx, rx) = channel::<int>();
- spawn(move|| {
+ Thread::spawn(move|| {
rx.recv();
- });
+ }).detach();
loop { tx.send(1) }
- } #[should_fail] }
+ }
- test! { fn port_gone_concurrent_shared() {
+ #[test]
+ #[should_fail]
+ fn port_gone_concurrent_shared() {
let (tx, rx) = channel::<int>();
let tx2 = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
rx.recv();
- });
+ }).detach();
loop {
tx.send(1);
tx2.send(1);
}
- } #[should_fail] }
+ }
- test! { fn smoke_chan_gone() {
+ #[test]
+ #[should_fail]
+ fn smoke_chan_gone() {
let (tx, rx) = channel::<int>();
drop(tx);
rx.recv();
- } #[should_fail] }
+ }
- test! { fn smoke_chan_gone_shared() {
+ #[test]
+ #[should_fail]
+ fn smoke_chan_gone_shared() {
let (tx, rx) = channel::<()>();
let tx2 = tx.clone();
drop(tx);
drop(tx2);
rx.recv();
- } #[should_fail] }
+ }
- test! { fn chan_gone_concurrent() {
+ #[test]
+ #[should_fail]
+ fn chan_gone_concurrent() {
let (tx, rx) = channel::<int>();
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(1);
tx.send(1);
- });
+ }).detach();
loop { rx.recv(); }
- } #[should_fail] }
+ }
- test! { fn stress() {
+ #[test]
+ fn stress() {
let (tx, rx) = channel::<int>();
- spawn(move|| {
+ let t = Thread::spawn(move|| {
for _ in range(0u, 10000) { tx.send(1i); }
});
for _ in range(0u, 10000) {
assert_eq!(rx.recv(), 1);
}
- } }
+ t.join().ok().unwrap();
+ }
- test! { fn stress_shared() {
+ #[test]
+ fn stress_shared() {
static AMT: uint = 10000;
static NTHREADS: uint = 8;
let (tx, rx) = channel::<int>();
- let (dtx, drx) = channel::<()>();
- spawn(move|| {
+ let t = Thread::spawn(move|| {
for _ in range(0, AMT * NTHREADS) {
assert_eq!(rx.recv(), 1);
}
Ok(..) => panic!(),
_ => {}
}
- dtx.send(());
});
for _ in range(0, NTHREADS) {
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
for _ in range(0, AMT) { tx.send(1); }
- });
+ }).detach();
}
drop(tx);
- drx.recv();
- } }
+ t.join().ok().unwrap();
+ }
#[test]
fn send_from_outside_runtime() {
let (tx1, rx1) = channel::<()>();
let (tx2, rx2) = channel::<int>();
- let (tx3, rx3) = channel::<()>();
- let tx4 = tx3.clone();
- spawn(move|| {
+ let t1 = Thread::spawn(move|| {
tx1.send(());
for _ in range(0i, 40) {
assert_eq!(rx2.recv(), 1);
}
- tx3.send(());
});
rx1.recv();
- spawn(move|| {
+ let t2 = Thread::spawn(move|| {
for _ in range(0i, 40) {
tx2.send(1);
}
- tx4.send(());
});
- rx3.recv();
- rx3.recv();
+ t1.join().ok().unwrap();
+ t2.join().ok().unwrap();
}
#[test]
fn recv_from_outside_runtime() {
let (tx, rx) = channel::<int>();
- let (dtx, drx) = channel();
- spawn(move|| {
+ let t = Thread::spawn(move|| {
for _ in range(0i, 40) {
assert_eq!(rx.recv(), 1);
}
- dtx.send(());
});
for _ in range(0u, 40) {
tx.send(1);
}
- drx.recv();
+ t.join().ok().unwrap();
}
#[test]
fn no_runtime() {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>();
- let (tx3, rx3) = channel::<()>();
- let tx4 = tx3.clone();
- spawn(move|| {
+ let t1 = Thread::spawn(move|| {
assert_eq!(rx1.recv(), 1);
tx2.send(2);
- tx4.send(());
});
- spawn(move|| {
+ let t2 = Thread::spawn(move|| {
tx1.send(1);
assert_eq!(rx2.recv(), 2);
- tx3.send(());
});
- rx3.recv();
- rx3.recv();
+ t1.join().ok().unwrap();
+ t2.join().ok().unwrap();
}
- test! { fn oneshot_single_thread_close_port_first() {
+ #[test]
+ fn oneshot_single_thread_close_port_first() {
// Simple test of closing without sending
let (_tx, rx) = channel::<int>();
drop(rx);
- } }
+ }
- test! { fn oneshot_single_thread_close_chan_first() {
+ #[test]
+ fn oneshot_single_thread_close_chan_first() {
// Simple test of closing without sending
let (tx, _rx) = channel::<int>();
drop(tx);
- } }
+ }
- test! { fn oneshot_single_thread_send_port_close() {
+ #[test]
+ #[should_fail]
+ fn oneshot_single_thread_send_port_close() {
// Testing that the sender cleans up the payload if receiver is closed
let (tx, rx) = channel::<Box<int>>();
drop(rx);
tx.send(box 0);
- } #[should_fail] }
+ }
- test! { fn oneshot_single_thread_recv_chan_close() {
+ #[test]
+ fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
let res = Thread::spawn(move|| {
let (tx, rx) = channel::<int>();
}).join();
// What is our res?
assert!(res.is_err());
- } }
+ }
- test! { fn oneshot_single_thread_send_then_recv() {
+ #[test]
+ fn oneshot_single_thread_send_then_recv() {
let (tx, rx) = channel::<Box<int>>();
tx.send(box 10);
assert!(rx.recv() == box 10);
- } }
+ }
- test! { fn oneshot_single_thread_try_send_open() {
+ #[test]
+ fn oneshot_single_thread_try_send_open() {
let (tx, rx) = channel::<int>();
assert!(tx.send_opt(10).is_ok());
assert!(rx.recv() == 10);
- } }
+ }
- test! { fn oneshot_single_thread_try_send_closed() {
+ #[test]
+ fn oneshot_single_thread_try_send_closed() {
let (tx, rx) = channel::<int>();
drop(rx);
assert!(tx.send_opt(10).is_err());
- } }
+ }
- test! { fn oneshot_single_thread_try_recv_open() {
+ #[test]
+ fn oneshot_single_thread_try_recv_open() {
let (tx, rx) = channel::<int>();
tx.send(10);
assert!(rx.recv_opt() == Ok(10));
- } }
+ }
- test! { fn oneshot_single_thread_try_recv_closed() {
+ #[test]
+ fn oneshot_single_thread_try_recv_closed() {
let (tx, rx) = channel::<int>();
drop(tx);
assert!(rx.recv_opt() == Err(()));
- } }
+ }
- test! { fn oneshot_single_thread_peek_data() {
+ #[test]
+ fn oneshot_single_thread_peek_data() {
let (tx, rx) = channel::<int>();
assert_eq!(rx.try_recv(), Err(Empty));
tx.send(10);
assert_eq!(rx.try_recv(), Ok(10));
- } }
+ }
- test! { fn oneshot_single_thread_peek_close() {
+ #[test]
+ fn oneshot_single_thread_peek_close() {
let (tx, rx) = channel::<int>();
drop(tx);
assert_eq!(rx.try_recv(), Err(Disconnected));
assert_eq!(rx.try_recv(), Err(Disconnected));
- } }
+ }
- test! { fn oneshot_single_thread_peek_open() {
+ #[test]
+ fn oneshot_single_thread_peek_open() {
let (_tx, rx) = channel::<int>();
assert_eq!(rx.try_recv(), Err(Empty));
- } }
+ }
- test! { fn oneshot_multi_task_recv_then_send() {
+ #[test]
+ fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = channel::<Box<int>>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
assert!(rx.recv() == box 10);
});
tx.send(box 10);
- } }
+ }
- test! { fn oneshot_multi_task_recv_then_close() {
+ #[test]
+ fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = channel::<Box<int>>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(tx);
});
let res = Thread::spawn(move|| {
assert!(rx.recv() == box 10);
}).join();
assert!(res.is_err());
- } }
+ }
- test! { fn oneshot_multi_thread_close_stress() {
+ #[test]
+ fn oneshot_multi_thread_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(rx);
});
drop(tx);
}
- } }
+ }
- test! { fn oneshot_multi_thread_send_close_stress() {
+ #[test]
+ fn oneshot_multi_thread_send_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(rx);
});
let _ = Thread::spawn(move|| {
tx.send(1);
}).join();
}
- } }
+ }
- test! { fn oneshot_multi_thread_recv_close_stress() {
+ #[test]
+ fn oneshot_multi_thread_recv_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
- spawn(move|| {
+ Thread::spawn(move|| {
let res = Thread::spawn(move|| {
rx.recv();
}).join();
assert!(res.is_err());
- });
- spawn(move|| {
- spawn(move|| {
+ }).detach();
+ let _t = Thread::spawn(move|| {
+ Thread::spawn(move|| {
drop(tx);
- });
+ }).detach();
});
}
- } }
+ }
- test! { fn oneshot_multi_thread_send_recv_stress() {
+ #[test]
+ fn oneshot_multi_thread_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
tx.send(box 10i);
});
- spawn(move|| {
- assert!(rx.recv() == box 10i);
- });
+ assert!(rx.recv() == box 10i);
}
- } }
+ }
- test! { fn stream_send_recv_stress() {
+ #[test]
+ fn stream_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel();
fn send(tx: Sender<Box<int>>, i: int) {
if i == 10 { return }
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(box i);
send(tx, i + 1);
- });
+ }).detach();
}
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
- spawn(move|| {
+ Thread::spawn(move|| {
assert!(rx.recv() == box i);
recv(rx, i + 1);
- });
+ }).detach();
}
}
- } }
+ }
- test! { fn recv_a_lot() {
+ #[test]
+ fn recv_a_lot() {
// Regression test that we don't run out of stack in scheduler context
let (tx, rx) = channel();
for _ in range(0i, 10000) { tx.send(()); }
for _ in range(0i, 10000) { rx.recv(); }
- } }
+ }
- test! { fn shared_chan_stress() {
+ #[test]
+ fn shared_chan_stress() {
let (tx, rx) = channel();
let total = stress_factor() + 100;
for _ in range(0, total) {
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(());
- });
+ }).detach();
}
for _ in range(0, total) {
rx.recv();
}
- } }
+ }
- test! { fn test_nested_recv_iter() {
+ #[test]
+ fn test_nested_recv_iter() {
let (tx, rx) = channel::<int>();
let (total_tx, total_rx) = channel::<int>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
tx.send(2);
drop(tx);
assert_eq!(total_rx.recv(), 6);
- } }
+ }
- test! { fn test_recv_iter_break() {
+ #[test]
+ fn test_recv_iter_break() {
let (tx, rx) = channel::<int>();
let (count_tx, count_rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
let _ = tx.send_opt(2);
drop(tx);
assert_eq!(count_rx.recv(), 4);
- } }
+ }
- test! { fn try_recv_states() {
+ #[test]
+ fn try_recv_states() {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx2.recv();
tx1.send(1);
tx3.send(());
tx2.send(());
rx3.recv();
assert_eq!(rx1.try_recv(), Err(Disconnected));
- } }
+ }
// This bug used to end up in a livelock inside of the Receiver destructor
// because the internal state of the Shared packet was corrupted
- test! { fn destroy_upgraded_shared_port_when_sender_still_active() {
+ #[test]
+ fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx.recv(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(());
// wait for the child task to exit before we exit
rx2.recv();
- }}
+ }
}
#[cfg(test)]
mod sync_tests {
- use prelude::*;
+ use prelude::v1::*;
use os;
+ use thread::Thread;
+ use super::*;
+ use str::from_str;
pub fn stress_factor() -> uint {
match os::getenv("RUST_TEST_STRESS") {
}
}
- test! { fn smoke() {
+ #[test]
+ fn smoke() {
let (tx, rx) = sync_channel::<int>(1);
tx.send(1);
assert_eq!(rx.recv(), 1);
- } }
+ }
- test! { fn drop_full() {
+ #[test]
+ fn drop_full() {
let (tx, _rx) = sync_channel(1);
tx.send(box 1i);
- } }
+ }
- test! { fn smoke_shared() {
+ #[test]
+ fn smoke_shared() {
let (tx, rx) = sync_channel::<int>(1);
tx.send(1);
assert_eq!(rx.recv(), 1);
let tx = tx.clone();
tx.send(1);
assert_eq!(rx.recv(), 1);
- } }
+ }
- test! { fn smoke_threads() {
+ #[test]
+ fn smoke_threads() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
tx.send(1);
});
assert_eq!(rx.recv(), 1);
- } }
+ }
- test! { fn smoke_port_gone() {
+ #[test]
+ #[should_fail]
+ fn smoke_port_gone() {
let (tx, rx) = sync_channel::<int>(0);
drop(rx);
tx.send(1);
- } #[should_fail] }
+ }
- test! { fn smoke_shared_port_gone2() {
+ #[test]
+ #[should_fail]
+ fn smoke_shared_port_gone2() {
let (tx, rx) = sync_channel::<int>(0);
drop(rx);
let tx2 = tx.clone();
drop(tx);
tx2.send(1);
- } #[should_fail] }
+ }
- test! { fn port_gone_concurrent() {
+ #[test]
+ #[should_fail]
+ fn port_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ Thread::spawn(move|| {
rx.recv();
- });
+ }).detach();
loop { tx.send(1) }
- } #[should_fail] }
+ }
- test! { fn port_gone_concurrent_shared() {
+ #[test]
+ #[should_fail]
+ fn port_gone_concurrent_shared() {
let (tx, rx) = sync_channel::<int>(0);
let tx2 = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
rx.recv();
- });
+ }).detach();
loop {
tx.send(1);
tx2.send(1);
}
- } #[should_fail] }
+ }
- test! { fn smoke_chan_gone() {
+ #[test]
+ #[should_fail]
+ fn smoke_chan_gone() {
let (tx, rx) = sync_channel::<int>(0);
drop(tx);
rx.recv();
- } #[should_fail] }
+ }
- test! { fn smoke_chan_gone_shared() {
+ #[test]
+ #[should_fail]
+ fn smoke_chan_gone_shared() {
let (tx, rx) = sync_channel::<()>(0);
let tx2 = tx.clone();
drop(tx);
drop(tx2);
rx.recv();
- } #[should_fail] }
+ }
- test! { fn chan_gone_concurrent() {
+ #[test]
+ #[should_fail]
+ fn chan_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(1);
tx.send(1);
- });
+ }).detach();
loop { rx.recv(); }
- } #[should_fail] }
+ }
- test! { fn stress() {
+ #[test]
+ fn stress() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ Thread::spawn(move|| {
for _ in range(0u, 10000) { tx.send(1); }
- });
+ }).detach();
for _ in range(0u, 10000) {
assert_eq!(rx.recv(), 1);
}
- } }
+ }
- test! { fn stress_shared() {
+ #[test]
+ fn stress_shared() {
static AMT: uint = 1000;
static NTHREADS: uint = 8;
let (tx, rx) = sync_channel::<int>(0);
let (dtx, drx) = sync_channel::<()>(0);
- spawn(move|| {
+ Thread::spawn(move|| {
for _ in range(0, AMT * NTHREADS) {
assert_eq!(rx.recv(), 1);
}
_ => {}
}
dtx.send(());
- });
+ }).detach();
for _ in range(0, NTHREADS) {
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
for _ in range(0, AMT) { tx.send(1); }
- });
+ }).detach();
}
drop(tx);
drx.recv();
- } }
+ }
- test! { fn oneshot_single_thread_close_port_first() {
+ #[test]
+ fn oneshot_single_thread_close_port_first() {
// Simple test of closing without sending
let (_tx, rx) = sync_channel::<int>(0);
drop(rx);
- } }
+ }
- test! { fn oneshot_single_thread_close_chan_first() {
+ #[test]
+ fn oneshot_single_thread_close_chan_first() {
// Simple test of closing without sending
let (tx, _rx) = sync_channel::<int>(0);
drop(tx);
- } }
+ }
- test! { fn oneshot_single_thread_send_port_close() {
+ #[test]
+ #[should_fail]
+ fn oneshot_single_thread_send_port_close() {
// Testing that the sender cleans up the payload if receiver is closed
let (tx, rx) = sync_channel::<Box<int>>(0);
drop(rx);
tx.send(box 0);
- } #[should_fail] }
+ }
- test! { fn oneshot_single_thread_recv_chan_close() {
+ #[test]
+ fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
let res = Thread::spawn(move|| {
let (tx, rx) = sync_channel::<int>(0);
}).join();
// What is our res?
assert!(res.is_err());
- } }
+ }
- test! { fn oneshot_single_thread_send_then_recv() {
+ #[test]
+ fn oneshot_single_thread_send_then_recv() {
let (tx, rx) = sync_channel::<Box<int>>(1);
tx.send(box 10);
assert!(rx.recv() == box 10);
- } }
+ }
- test! { fn oneshot_single_thread_try_send_open() {
+ #[test]
+ fn oneshot_single_thread_try_send_open() {
let (tx, rx) = sync_channel::<int>(1);
assert_eq!(tx.try_send(10), Ok(()));
assert!(rx.recv() == 10);
- } }
+ }
- test! { fn oneshot_single_thread_try_send_closed() {
+ #[test]
+ fn oneshot_single_thread_try_send_closed() {
let (tx, rx) = sync_channel::<int>(0);
drop(rx);
assert_eq!(tx.try_send(10), Err(RecvDisconnected(10)));
- } }
+ }
- test! { fn oneshot_single_thread_try_send_closed2() {
+ #[test]
+ fn oneshot_single_thread_try_send_closed2() {
let (tx, _rx) = sync_channel::<int>(0);
assert_eq!(tx.try_send(10), Err(Full(10)));
- } }
+ }
- test! { fn oneshot_single_thread_try_recv_open() {
+ #[test]
+ fn oneshot_single_thread_try_recv_open() {
let (tx, rx) = sync_channel::<int>(1);
tx.send(10);
assert!(rx.recv_opt() == Ok(10));
- } }
+ }
- test! { fn oneshot_single_thread_try_recv_closed() {
+ #[test]
+ fn oneshot_single_thread_try_recv_closed() {
let (tx, rx) = sync_channel::<int>(0);
drop(tx);
assert!(rx.recv_opt() == Err(()));
- } }
+ }
- test! { fn oneshot_single_thread_peek_data() {
+ #[test]
+ fn oneshot_single_thread_peek_data() {
let (tx, rx) = sync_channel::<int>(1);
assert_eq!(rx.try_recv(), Err(Empty));
tx.send(10);
assert_eq!(rx.try_recv(), Ok(10));
- } }
+ }
- test! { fn oneshot_single_thread_peek_close() {
+ #[test]
+ fn oneshot_single_thread_peek_close() {
let (tx, rx) = sync_channel::<int>(0);
drop(tx);
assert_eq!(rx.try_recv(), Err(Disconnected));
assert_eq!(rx.try_recv(), Err(Disconnected));
- } }
+ }
- test! { fn oneshot_single_thread_peek_open() {
+ #[test]
+ fn oneshot_single_thread_peek_open() {
let (_tx, rx) = sync_channel::<int>(0);
assert_eq!(rx.try_recv(), Err(Empty));
- } }
+ }
- test! { fn oneshot_multi_task_recv_then_send() {
+ #[test]
+ fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = sync_channel::<Box<int>>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
assert!(rx.recv() == box 10);
});
tx.send(box 10);
- } }
+ }
- test! { fn oneshot_multi_task_recv_then_close() {
+ #[test]
+ fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = sync_channel::<Box<int>>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(tx);
});
let res = Thread::spawn(move|| {
assert!(rx.recv() == box 10);
}).join();
assert!(res.is_err());
- } }
+ }
- test! { fn oneshot_multi_thread_close_stress() {
+ #[test]
+ fn oneshot_multi_thread_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(rx);
});
drop(tx);
}
- } }
+ }
- test! { fn oneshot_multi_thread_send_close_stress() {
+ #[test]
+ fn oneshot_multi_thread_send_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(rx);
});
let _ = Thread::spawn(move || {
tx.send(1);
}).join();
}
- } }
+ }
- test! { fn oneshot_multi_thread_recv_close_stress() {
+ #[test]
+ fn oneshot_multi_thread_recv_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let res = Thread::spawn(move|| {
rx.recv();
}).join();
assert!(res.is_err());
});
- spawn(move|| {
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
+ Thread::spawn(move|| {
drop(tx);
- });
+ }).detach();
});
}
- } }
+ }
- test! { fn oneshot_multi_thread_send_recv_stress() {
+ #[test]
+ fn oneshot_multi_thread_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<Box<int>>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
tx.send(box 10i);
});
- spawn(move|| {
- assert!(rx.recv() == box 10i);
- });
+ assert!(rx.recv() == box 10i);
}
- } }
+ }
- test! { fn stream_send_recv_stress() {
+ #[test]
+ fn stream_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<Box<int>>(0);
fn send(tx: SyncSender<Box<int>>, i: int) {
if i == 10 { return }
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(box i);
send(tx, i + 1);
- });
+ }).detach();
}
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
- spawn(move|| {
+ Thread::spawn(move|| {
assert!(rx.recv() == box i);
recv(rx, i + 1);
- });
+ }).detach();
}
}
- } }
+ }
- test! { fn recv_a_lot() {
+ #[test]
+ fn recv_a_lot() {
// Regression test that we don't run out of stack in scheduler context
let (tx, rx) = sync_channel(10000);
for _ in range(0u, 10000) { tx.send(()); }
for _ in range(0u, 10000) { rx.recv(); }
- } }
+ }
- test! { fn shared_chan_stress() {
+ #[test]
+ fn shared_chan_stress() {
let (tx, rx) = sync_channel(0);
let total = stress_factor() + 100;
for _ in range(0, total) {
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(());
- });
+ }).detach();
}
for _ in range(0, total) {
rx.recv();
}
- } }
+ }
- test! { fn test_nested_recv_iter() {
+ #[test]
+ fn test_nested_recv_iter() {
let (tx, rx) = sync_channel::<int>(0);
let (total_tx, total_rx) = sync_channel::<int>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
tx.send(2);
drop(tx);
assert_eq!(total_rx.recv(), 6);
- } }
+ }
- test! { fn test_recv_iter_break() {
+ #[test]
+ fn test_recv_iter_break() {
let (tx, rx) = sync_channel::<int>(0);
let (count_tx, count_rx) = sync_channel(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
let _ = tx.try_send(2);
drop(tx);
assert_eq!(count_rx.recv(), 4);
- } }
+ }
- test! { fn try_recv_states() {
+ #[test]
+ fn try_recv_states() {
let (tx1, rx1) = sync_channel::<int>(1);
let (tx2, rx2) = sync_channel::<()>(1);
let (tx3, rx3) = sync_channel::<()>(1);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx2.recv();
tx1.send(1);
tx3.send(());
tx2.send(());
rx3.recv();
assert_eq!(rx1.try_recv(), Err(Disconnected));
- } }
+ }
// This bug used to end up in a livelock inside of the Receiver destructor
// because the internal state of the Shared packet was corrupted
- test! { fn destroy_upgraded_shared_port_when_sender_still_active() {
+ #[test]
+ fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = sync_channel::<()>(0);
let (tx2, rx2) = sync_channel::<()>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx.recv(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(());
// wait for the child task to exit before we exit
rx2.recv();
- } }
+ }
- test! { fn send_opt1() {
+ #[test]
+ fn send_opt1() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| { rx.recv(); });
+ let _t = Thread::spawn(move|| { rx.recv(); });
assert_eq!(tx.send_opt(1), Ok(()));
- } }
+ }
- test! { fn send_opt2() {
+ #[test]
+ fn send_opt2() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| { drop(rx); });
+ let _t = Thread::spawn(move|| { drop(rx); });
assert_eq!(tx.send_opt(1), Err(1));
- } }
+ }
- test! { fn send_opt3() {
+ #[test]
+ fn send_opt3() {
let (tx, rx) = sync_channel::<int>(1);
assert_eq!(tx.send_opt(1), Ok(()));
- spawn(move|| { drop(rx); });
+ let _t = Thread::spawn(move|| { drop(rx); });
assert_eq!(tx.send_opt(1), Err(1));
- } }
+ }
- test! { fn send_opt4() {
+ #[test]
+ fn send_opt4() {
let (tx, rx) = sync_channel::<int>(0);
let tx2 = tx.clone();
let (done, donerx) = channel();
let done2 = done.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
assert_eq!(tx.send_opt(1), Err(1));
done.send(());
});
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
assert_eq!(tx2.send_opt(2), Err(2));
done2.send(());
});
drop(rx);
donerx.recv();
donerx.recv();
- } }
+ }
- test! { fn try_send1() {
+ #[test]
+ fn try_send1() {
let (tx, _rx) = sync_channel::<int>(0);
assert_eq!(tx.try_send(1), Err(Full(1)));
- } }
+ }
- test! { fn try_send2() {
+ #[test]
+ fn try_send2() {
let (tx, _rx) = sync_channel::<int>(1);
assert_eq!(tx.try_send(1), Ok(()));
assert_eq!(tx.try_send(1), Err(Full(1)));
- } }
+ }
- test! { fn try_send3() {
+ #[test]
+ fn try_send3() {
let (tx, rx) = sync_channel::<int>(1);
assert_eq!(tx.try_send(1), Ok(()));
drop(rx);
assert_eq!(tx.try_send(1), Err(RecvDisconnected(1)));
- } }
-
- test! { fn try_send4() {
- let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
- for _ in range(0u, 1000) { Thread::yield_now(); }
- assert_eq!(tx.try_send(1), Ok(()));
- });
- assert_eq!(rx.recv(), 1);
- } #[ignore(reason = "flaky on libnative")] }
+ }
- test! { fn issue_15761() {
+ #[test]
+ fn issue_15761() {
fn repro() {
let (tx1, rx1) = sync_channel::<()>(3);
let (tx2, rx2) = sync_channel::<()>(3);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx1.recv();
tx2.try_send(()).unwrap();
});
for _ in range(0u, 100) {
repro()
}
- } }
+ }
}
#[cfg(test)]
mod tests {
- use prelude::*;
-
- use alloc::arc::Arc;
+ use prelude::v1::*;
+ use comm::channel;
use super::{Queue, Data, Empty, Inconsistent};
+ use sync::Arc;
+ use thread::Thread;
#[test]
fn test_full() {
for _ in range(0, nthreads) {
let tx = tx.clone();
let q = q.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
for i in range(0, nmsgs) {
q.push(i);
}
tx.send(());
- });
+ }).detach();
}
let mut i = 0u;
//! # Example
//!
//! ```rust
+//! use std::comm::channel;
+//!
//! let (tx1, rx1) = channel();
//! let (tx2, rx2) = channel();
//!
#[cfg(test)]
#[allow(unused_imports)]
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
// (std::comm points at the wrong one)
})
}
- test! { fn smoke() {
+ #[test]
+ fn smoke() {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>();
tx1.send(1);
select! {
bar = rx2.recv_opt() => { assert_eq!(bar, Err(())); }
}
- } }
+ }
- test! { fn smoke2() {
+ #[test]
+ fn smoke2() {
let (_tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>();
let (_tx3, rx3) = channel::<int>();
_foo = rx4.recv() => { panic!("4") },
foo = rx5.recv() => { assert_eq!(foo, 4); }
}
- } }
+ }
- test! { fn closed() {
+ #[test]
+ fn closed() {
let (_tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>();
drop(tx2);
_a1 = rx1.recv_opt() => { panic!() },
a2 = rx2.recv_opt() => { assert_eq!(a2, Err(())); }
}
- } }
+ }
- test! { fn unblocks() {
+ #[test]
+ fn unblocks() {
let (tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<int>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for _ in range(0u, 20) { Thread::yield_now(); }
tx1.send(1);
rx3.recv();
a = rx1.recv_opt() => { assert_eq!(a, Err(())); },
_b = rx2.recv() => { panic!() }
}
- } }
+ }
- test! { fn both_ready() {
+ #[test]
+ fn both_ready() {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for _ in range(0u, 20) { Thread::yield_now(); }
tx1.send(1);
tx2.send(2);
assert_eq!(rx1.try_recv(), Err(Empty));
assert_eq!(rx2.try_recv(), Err(Empty));
tx3.send(());
- } }
+ }
- test! { fn stress() {
+ #[test]
+ fn stress() {
static AMT: int = 10000;
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for i in range(0, AMT) {
if i % 2 == 0 {
tx1.send(i);
}
tx3.send(());
}
- } }
+ }
- test! { fn cloning() {
+ #[test]
+ fn cloning() {
let (tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx3.recv();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty));
_i2 = rx2.recv() => panic!()
}
tx3.send(());
- } }
+ }
- test! { fn cloning2() {
+ #[test]
+ fn cloning2() {
let (tx1, rx1) = channel::<int>();
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx3.recv();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty));
_i2 = rx2.recv() => panic!()
}
tx3.send(());
- } }
+ }
- test! { fn cloning3() {
+ #[test]
+ fn cloning3() {
let (tx1, rx1) = channel::<()>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let s = Select::new();
let mut h1 = s.handle(&rx1);
let mut h2 = s.handle(&rx2);
drop(tx1.clone());
tx2.send(());
rx3.recv();
- } }
+ }
- test! { fn preflight1() {
+ #[test]
+ fn preflight1() {
let (tx, rx) = channel();
tx.send(());
select! {
() = rx.recv() => {}
}
- } }
+ }
- test! { fn preflight2() {
+ #[test]
+ fn preflight2() {
let (tx, rx) = channel();
tx.send(());
tx.send(());
select! {
() = rx.recv() => {}
}
- } }
+ }
- test! { fn preflight3() {
+ #[test]
+ fn preflight3() {
let (tx, rx) = channel();
drop(tx.clone());
tx.send(());
select! {
() = rx.recv() => {}
}
- } }
+ }
- test! { fn preflight4() {
+ #[test]
+ fn preflight4() {
let (tx, rx) = channel();
tx.send(());
let s = Select::new();
let mut h = s.handle(&rx);
unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id);
- } }
+ }
- test! { fn preflight5() {
+ #[test]
+ fn preflight5() {
let (tx, rx) = channel();
tx.send(());
tx.send(());
let mut h = s.handle(&rx);
unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id);
- } }
+ }
- test! { fn preflight6() {
+ #[test]
+ fn preflight6() {
let (tx, rx) = channel();
drop(tx.clone());
tx.send(());
let mut h = s.handle(&rx);
unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id);
- } }
+ }
- test! { fn preflight7() {
+ #[test]
+ fn preflight7() {
let (tx, rx) = channel::<()>();
drop(tx);
let s = Select::new();
let mut h = s.handle(&rx);
unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id);
- } }
+ }
- test! { fn preflight8() {
+ #[test]
+ fn preflight8() {
let (tx, rx) = channel();
tx.send(());
drop(tx);
let mut h = s.handle(&rx);
unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id);
- } }
+ }
- test! { fn preflight9() {
+ #[test]
+ fn preflight9() {
let (tx, rx) = channel();
drop(tx.clone());
tx.send(());
let mut h = s.handle(&rx);
unsafe { h.add(); }
assert_eq!(s.wait2(false), h.id);
- } }
+ }
- test! { fn oneshot_data_waiting() {
+ #[test]
+ fn oneshot_data_waiting() {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
select! {
() = rx1.recv() => {}
}
for _ in range(0u, 100) { Thread::yield_now() }
tx1.send(());
rx2.recv();
- } }
+ }
- test! { fn stream_data_waiting() {
+ #[test]
+ fn stream_data_waiting() {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
tx1.send(());
tx1.send(());
rx1.recv();
rx1.recv();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
select! {
() = rx1.recv() => {}
}
for _ in range(0u, 100) { Thread::yield_now() }
tx1.send(());
rx2.recv();
- } }
+ }
- test! { fn shared_data_waiting() {
+ #[test]
+ fn shared_data_waiting() {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
drop(tx1.clone());
tx1.send(());
rx1.recv();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
select! {
() = rx1.recv() => {}
}
for _ in range(0u, 100) { Thread::yield_now() }
tx1.send(());
rx2.recv();
- } }
+ }
- test! { fn sync1() {
+ #[test]
+ fn sync1() {
let (tx, rx) = sync_channel::<int>(1);
tx.send(1);
select! {
n = rx.recv() => { assert_eq!(n, 1); }
}
- } }
+ }
- test! { fn sync2() {
+ #[test]
+ fn sync2() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for _ in range(0u, 100) { Thread::yield_now() }
tx.send(1);
});
select! {
n = rx.recv() => { assert_eq!(n, 1); }
}
- } }
+ }
- test! { fn sync3() {
+ #[test]
+ fn sync3() {
let (tx1, rx1) = sync_channel::<int>(0);
let (tx2, rx2): (Sender<int>, Receiver<int>) = channel();
- spawn(move|| { tx1.send(1); });
- spawn(move|| { tx2.send(2); });
+ let _t = Thread::spawn(move|| { tx1.send(1); });
+ let _t = Thread::spawn(move|| { tx2.send(2); });
select! {
n = rx1.recv() => {
assert_eq!(n, 1);
assert_eq!(rx1.recv(), 1);
}
}
- } }
+ }
}
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use sync::Arc;
use super::Queue;
+ use thread::Thread;
+ use comm::channel;
#[test]
fn smoke() {
let (tx, rx) = channel();
let q2 = q.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for _ in range(0u, 100000) {
loop {
match q2.pop() {
#![experimental]
#![allow(missing_docs)]
-use prelude::*;
+use prelude::v1::*;
+
+use c_str::ToCStr;
use mem;
use os;
use str;
#[cfg(all(test, not(target_os = "ios")))]
mod test {
use super::*;
- use prelude::*;
+ use prelude::v1::*;
use libc;
use mem;
pub mod dl {
use self::Rtld::*;
- use prelude::*;
- use c_str::CString;
+ use prelude::v1::*;
+ use c_str::{CString, ToCStr};
use libc;
use ptr;
//! }
//! ```
-use prelude::*;
+use prelude::v1::*;
use str::Utf8Error;
use string::{FromUtf8Error, FromUtf16Error};
#![experimental]
-use prelude::*;
+use prelude::v1::*;
use any::{Any, AnyRefExt};
use cell::RefCell;
mod test {
extern crate test;
use io;
- use prelude::*;
+ use prelude::v1::*;
use super::*;
use super::super::{IoResult, EndOfFile};
use super::super::mem::MemReader;
/// # Example
///
/// ```
+/// use std::comm::channel;
/// use std::io::ChanReader;
///
/// let (tx, rx) = channel();
///
/// ```
/// # #![allow(unused_must_use)]
+/// use std::comm::channel;
/// use std::io::ChanWriter;
///
/// let (tx, rx) = channel();
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
+
+ use comm::channel;
use super::*;
use io;
use thread::Thread;
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use io;
use io::{MemReader, BytesReader};
mod bench {
extern crate test;
- use prelude::*;
+ use prelude::v1::*;
use self::test::Bencher;
// why is this a macro? wouldn't an inlined function work just as well?
#[allow(unused_variables)]
#[allow(unused_mut)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType};
use io;
use str;
#[cfg(test)]
mod test {
extern crate "test" as test_crate;
+ use prelude::v1::*;
+
use super::*;
- use io::{SeekSet, SeekCur, SeekEnd, Reader, Writer, Seek};
- use prelude::{Ok, Err, range, Vec, Buffer, AsSlice, SliceExt, IteratorExt, CloneSliceExt};
+ use io::{SeekSet, SeekCur, SeekEnd};
use io;
use self::test_crate::Bencher;
use int;
use iter::{Iterator, IteratorExt};
use mem::transmute;
-use ops::{BitOr, BitXor, BitAnd, Sub, Not, FnOnce};
+use ops::FnOnce;
use option::Option;
use option::Option::{Some, None};
use os;
#[cfg(test)]
mod tests {
use self::BadReaderBehavior::*;
- use super::{IoResult, Reader, MemReader, NoProgress, InvalidInput, Writer};
- use prelude::{Ok, Vec, Buffer, CloneSliceExt};
+ use super::{IoResult, MemReader, NoProgress, InvalidInput};
+ use prelude::v1::*;
use uint;
#[deriving(Clone, PartialEq, Show)]
// permission without help of apk
#[cfg(all(test, not(target_os = "android")))]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use super::*;
use io::net::ip::*;
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use super::*;
use str::FromStr;
#![allow(missing_docs)]
-use prelude::*;
+use prelude::v1::*;
+use c_str::ToCStr;
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::UnixListener as UnixListenerImp;
+use sys::pipe::UnixStream as UnixStreamImp;
+use time::Duration;
use sys_common;
}
#[cfg(test)]
-#[allow(experimental)]
mod tests {
- use super::*;
- use io::*;
- use io::test::*;
- use prelude::{Ok, Err, spawn, range, drop, Some, None, channel, Send, FnOnce, Clone};
+ use prelude::v1::*;
+
+ use comm::channel;
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;
pub fn smalltest<F,G>(server: F, client: G)
let mut acceptor = UnixListener::bind(&path1).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
match UnixStream::connect(&path2) {
Ok(c) => client(c),
Err(e) => panic!("failed connect: {}", e),
Err(e) => panic!("failed listen: {}", e),
};
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for _ in range(0u, times) {
let mut stream = UnixStream::connect(&path2);
match stream.write(&[100]) {
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr);
let mut buf = [0, 0];
debug!("client reading");
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
rx1.recv();
debug!("writer writing");
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr);
s.write(&[1]).unwrap();
rx.recv();
let s2 = s1.clone();
let (done, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr);
let buf = &mut [0, 1];
s.read(buf).unwrap();
let s2 = s1.clone();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
tx.send(());
// continue to receive any pending connections.
let (tx, rx) = channel();
let addr2 = addr.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
tx.send(UnixStream::connect(&addr2).unwrap());
});
let l = rx.recv();
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
let addr2 = addr.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(UnixStream::connect(&addr2).unwrap());
});
a.accept().unwrap();
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
- });
+ }).detach();
let mut b = [0];
let mut s = UnixStream::connect(&addr).unwrap();
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = UnixStream::connect(&addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(());
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
s.set_timeout(Some(20));
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
let mut amt = 0;
}
}
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
s.set_read_timeout(Some(20));
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
s.set_write_timeout(Some(20));
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_ok());
tx2.send(());
let mut a2 = a.clone();
let addr2 = addr.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr);
});
let (tx, rx) = channel();
let tx2 = tx.clone();
- 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 = a; tx.send(a.accept()) });
+ let _t = Thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
let addr2 = addr.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _ = UnixStream::connect(&addr);
});
let mut a2 = a.clone();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut a = a;
tx.send(a.accept());
});
/// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();
/// let stream2 = stream.clone();
///
- /// Thread::spawn(move|| {
+ /// let _t = Thread::spawn(move|| {
/// // close this stream after one second
/// timer::sleep(Duration::seconds(1));
/// let mut stream = stream2;
/// use std::io::{Acceptor, Listener};
/// 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
-/// let mut acceptor = listener.listen();
+/// let mut acceptor = listener.listen().unwrap();
///
/// fn handle_client(mut stream: TcpStream) {
/// // ...
/// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap();
/// let a2 = a.clone();
///
- /// Thread::spawn(move|| {
+ /// let _t = Thread::spawn(move|| {
/// let mut a2 = a2;
/// for socket in a2.incoming() {
/// match socket {
#[cfg(test)]
#[allow(experimental)]
mod test {
+ use prelude::v1::*;
+
+ use comm::channel;
+ use thread::Thread;
use io::net::tcp::*;
use io::net::ip::*;
use io::{EndOfFile, TimedOut, IoError, ShortWrite, OtherIoError, ConnectionAborted};
use io::{ConnectionRefused, ConnectionReset, BrokenPipe, NotConnected};
use io::{PermissionDenied, Listener, Acceptor};
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
#[cfg_attr(any(windows, target_os = "android"), ignore)]
let listener = TcpListener::bind(socket_addr);
let mut acceptor = listener.listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(("localhost", socket_addr.port));
stream.write(&[144]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(("localhost", addr.port));
stream.write(&[64]).unwrap();
});
let addr = next_test_ip4();
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));
stream.write(&[44]).unwrap();
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(("::1", addr.port));
stream.write(&[66]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(());
});
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(());
});
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for _ in range(0, max) {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
for _ in range(0, max) {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
let addr = next_test_ip4();
let acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
let addr = next_test_ip6();
let acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
pub fn peer_name(addr: SocketAddr) {
let acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut acceptor = acceptor;
acceptor.accept().unwrap();
});
fn partial_read() {
let addr = next_test_ip4();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut srv = TcpListener::bind(addr).listen().unwrap();
tx.send(());
let mut cl = srv.accept().unwrap();
let addr = next_test_ip4();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
rx.recv();
let _stream = TcpStream::connect(addr).unwrap();
// Close
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 0];
assert_eq!(s.read(&mut buf), Ok(1));
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
rx1.recv();
s2.write(&[1]).unwrap();
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s = TcpStream::connect(addr);
s.write(&[1]).unwrap();
rx.recv();
let s2 = s1.clone();
let (done, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 1];
s.read(&mut buf).unwrap();
let s2 = s1.clone();
let (done, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
done.send(());
fn shutdown_smoke() {
let addr = next_test_ip4();
let a = TcpListener::bind(addr).unwrap().listen();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut a = a;
let mut c = a.accept().unwrap();
assert_eq!(c.read_to_end(), Ok(vec!()));
// flakiness.
if !cfg!(target_os = "freebsd") {
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
tx.send(TcpStream::connect(addr).unwrap());
});
let _l = rx.recv();
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
drop(TcpStream::connect(addr).unwrap());
});
a.accept().unwrap();
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
- });
+ }).detach();
let mut b = [0];
let mut s = TcpStream::connect(addr).unwrap();
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = TcpStream::connect(addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(());
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
s.set_timeout(Some(20));
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
let mut amt = 0;
}
}
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
s.set_read_timeout(Some(20));
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
s.set_write_timeout(Some(20));
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert_eq!(s.write(&[0]), Ok(()));
let _ = rx.recv_opt();
- });
+ }).detach();
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut s2 = s2;
assert_eq!(s2.read(&mut [0]), Ok(1));
tx2.send(());
let (tx, rx) = channel();
let (txdone, rxdone) = channel();
let txdone2 = txdone.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut tcp = TcpStream::connect(addr).unwrap();
rx.recv();
tcp.write_u8(0).unwrap();
let tcp = accept.accept().unwrap();
let tcp2 = tcp.clone();
let txdone3 = txdone.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut tcp2 = tcp2;
tcp2.read_u8().unwrap();
txdone3.send(());
let mut a = l.listen().unwrap();
let mut a2 = a.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _ = TcpStream::connect(addr);
});
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _ = TcpStream::connect(addr);
});
let (tx, rx) = channel();
let tx2 = tx.clone();
- 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 = a; tx.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);
});
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _ = TcpStream::connect(addr);
});
let mut a2 = a.clone();
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut a = a;
tx.send(a.accept());
});
#[cfg(test)]
#[allow(experimental)]
mod test {
- use super::*;
+ use prelude::v1::*;
+
+ use comm::channel;
use io::net::ip::*;
- use io::{ShortWrite, IoError, TimedOut, PermissionDenied};
+ use io::{IoError, ShortWrite, TimedOut, PermissionDenied};
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
#[cfg_attr(any(windows, target_os = "android"), ignore)]
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx1.recv();
let client_ip = next_test_ip6();
let (tx, rx) = channel::<()>();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx.recv();
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
- let send_as = |&: ip, val: &[u8]| {
+ let _t = Thread::spawn(move|| {
+ let send_as = |&:ip, val: &[u8]| {
match UdpSocket::bind(ip) {
Ok(client) => {
let client = box client;
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(client) => {
let client = box client;
let mut sock1 = UdpSocket::bind(addr1).unwrap();
let sock2 = UdpSocket::bind(addr2).unwrap();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 0];
assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1)));
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut sock3 = sock3;
rx1.recv();
sock3.send_to(&[1], addr2).unwrap();
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut sock2 = sock2;
sock2.send_to(&[1], addr1).unwrap();
rx.recv();
let sock3 = sock1.clone();
let (done, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut sock3 = sock3;
let mut buf = [0, 0];
sock3.recv_from(&mut buf).unwrap();
let (tx, rx) = channel();
let (serv_tx, serv_rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 1];
let (done, rx) = channel();
let tx2 = tx.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut sock3 = sock3;
match sock3.send_to(&[1], addr2) {
Ok(..) => { let _ = tx2.send_opt(()); }
let (tx, rx) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut a = a2;
assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1)));
assert_eq!(a.send_to(&[0], addr1), Ok(()));
#![allow(missing_docs)]
-use prelude::*;
+use prelude::v1::*;
use io::IoResult;
use libc;
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
+
+ use comm::channel;
+ use thread::Thread;
#[test]
fn partial_read() {
let out = PipeStream::open(writer);
let mut input = PipeStream::open(reader);
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut out = out;
out.write(&[10]).unwrap();
rx.recv(); // don't close the pipe until the other read has finished
pub use self::StdioContainer::*;
pub use self::ProcessExit::*;
-use prelude::*;
+use prelude::v1::*;
+use c_str::{CString, ToCStr};
+use collections::HashMap;
+use comm::{channel, Receiver};
use fmt;
-use os;
+use hash::Hash;
+use io::pipe::{PipeStream, PipePair};
use io::{IoResult, IoError};
use io;
use libc;
-use c_str::CString;
-use collections::HashMap;
-use hash::Hash;
-#[cfg(windows)]
-use std::hash::sip::SipState;
-use io::pipe::{PipeStream, PipePair};
+use os;
use path::BytesContainer;
-use thread::Thread;
-
-use sys;
use sys::fs::FileDesc;
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
/// SIGTERM on unix platforms.
#[cfg(test)]
mod tests {
- #![allow(unused_imports)]
+ use prelude::v1::*;
- use super::*;
+ use comm::channel;
+ use io::fs::PathExtensions;
use io::timer::*;
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 str;
+ use super::*;
+ use thread::Thread;
+ use time::Duration;
// FIXME(#10380) these tests should not all be ignored on android.
fn wait_timeout2() {
let (tx, rx) = channel();
let tx2 = tx.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);
p.signal_kill().unwrap();
tx.send(());
});
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use super::super::mem::*;
use io;
#[cfg(test)]
mod tests {
+ use prelude::v1::*;
+
use super::*;
- use prelude::*;
+ use comm::channel;
+ use thread::Thread;
#[test]
fn smoke() {
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
set_stdout(box w);
println!("hello!");
});
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- spawn(move|| {
+ let _t = Thread::spawn(move || -> () {
set_stderr(box w);
panic!("my special message");
});
#![macro_escape]
+use prelude::v1::*;
+
use libc;
use os;
-use prelude::*;
use std::io::net::ip::*;
use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use super::Timer;
+ use thread::Thread;
use time::Duration;
#[test]
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- spawn(move|| {
+ Thread::spawn(move|| {
let _ = timer_rx.recv_opt();
- });
+ }).detach();
// when we drop the TimerWatcher we're going to destroy the channel,
// which must wake up the task on the other end
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- spawn(move|| {
+ Thread::spawn(move|| {
let _ = timer_rx.recv_opt();
- });
+ }).detach();
timer.oneshot(Duration::milliseconds(1));
}
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- spawn(move|| {
+ Thread::spawn(move|| {
let _ = timer_rx.recv_opt();
- });
+ }).detach();
timer.sleep(Duration::milliseconds(1));
}
//! Utility implementations of Reader and Writer
-use prelude::*;
+use prelude::v1::*;
use cmp;
use io;
use slice::bytes::MutableByteVector;
#[cfg(test)]
mod test {
+ use prelude::v1::*;
+
use io::{MemReader, ByRefReader};
use io;
- use boxed::Box;
use super::*;
- use prelude::{Ok, range, Vec, Buffer, Writer, Reader, ToString, AsSlice};
#[test]
fn test_limit_reader_unlimited() {
pub use cell; // used for tls!
pub use thread_local; // used for thread_local!
pub use kinds; // used for tls!
+ pub use ops; // used for bitflags!
// The test runner calls ::std::os::args() but really wants realstd
#[cfg(test)] pub use realstd::os as os;
///
/// ```
/// use std::thread::Thread;
+/// use std::comm::channel;
///
/// let (tx1, rx1) = channel();
/// let (tx2, rx2) = channel();
#![allow(unsigned_negation)]
#![doc(primitive = "f32")]
-use prelude::*;
+use prelude::v1::*;
use intrinsics;
use libc::c_int;
#![allow(missing_docs)]
#![doc(primitive = "f64")]
-use prelude::*;
+use prelude::v1::*;
use intrinsics;
use libc::c_int;
#[cfg(test)]
mod tests {
- use prelude::{range, Some, None, Option, IteratorExt};
- use super::{from_int, from_uint, from_i32, from_i64, from_u64, from_u32};
- use super::{from_f64, from_f32, from_u16, from_i16, from_u8, from_i8, Int};
- use super::{cast, NumCast, ToPrimitive, FromPrimitive, UnsignedInt};
+ use prelude::v1::*;
+ use super::*;
use i8;
use i16;
use i32;
extern crate test;
use self::test::Bencher;
use num::Int;
- use prelude::*;
+ use prelude::v1::*;
#[bench]
fn bench_pow_function(b: &mut Bencher) {
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use num::FromStrRadix;
+ use str::from_str;
#[test]
pub fn test_from_str() {
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use option;
use os::{env, getcwd, getenv, make_absolute};
use os::{split_paths, join_paths, setenv, unsetenv};
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
+ use c_str::ToCStr;
+ use path::{WindowsPath, PosixPath};
#[test]
fn test_cstring() {
#[cfg(test)]
mod tests {
use super::*;
- use prelude::Option::{mod, Some, None};
- use prelude::{Vec, Clone, AsSlice, SliceExt, CloneSliceExt, IteratorExt};
- use prelude::{DoubleEndedIteratorExt, Str, StrExt, ToString, GenericPath};
- use str;
+
+ use clone::Clone;
+ use iter::{IteratorExt, DoubleEndedIteratorExt};
+ use option::Option::{mod, Some, None};
+ use path::GenericPath;
+ use slice::{AsSlice, SliceExt, CloneSliceExt};
+ use str::{mod, Str, StrExt};
+ use string::ToString;
+ use vec::Vec;
macro_rules! t {
(s: $path:expr, $exp:expr) => (
extern crate test;
use self::test::Bencher;
use super::*;
- use prelude::{Clone, GenericPath};
+ use prelude::v1::{Clone, GenericPath};
#[bench]
fn join_home_dir(b: &mut Bencher) {
#[cfg(test)]
mod tests {
use super::*;
- use prelude::Option::{mod, Some, None};
- use prelude::{Vec, Clone, AsSlice, SliceExt, CloneSliceExt, IteratorExt};
- use prelude::{DoubleEndedIteratorExt, Str, ToString, GenericPath};
use super::PathPrefix::*;
use super::parse_prefix;
+ use clone::Clone;
+ use iter::{IteratorExt, DoubleEndedIteratorExt};
+ use option::Option::{mod, Some, None};
+ use path::GenericPath;
+ use slice::{AsSlice, SliceExt, CloneSliceExt};
+ use str::Str;
+ use string::ToString;
+ use vec::Vec;
+
macro_rules! t {
(s: $path:expr, $exp:expr) => (
{
+++ /dev/null
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! The Rust prelude
-//!
-//! Because `std` is required by most serious Rust software, it is
-//! imported at the topmost level of every crate by default, as if the
-//! first line of each crate was
-//!
-//! ```ignore
-//! extern crate std;
-//! ```
-//!
-//! This means that the contents of std can be accessed from any context
-//! with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`,
-//! etc.
-//!
-//! Additionally, `std` contains a `prelude` module that reexports many of the
-//! most common traits, types and functions. The contents of the prelude are
-//! imported into every *module* by default. Implicitly, all modules behave as if
-//! they contained the following prologue:
-//!
-//! ```ignore
-//! use std::prelude::*;
-//! ```
-//!
-//! The prelude is primarily concerned with exporting *traits* that are so
-//! pervasive that it would be obnoxious to import for every use, particularly
-//! those that define methods on primitive types. It does include a few
-//! particularly useful standalone functions, like `from_str`, `range`, and
-//! `drop`, `spawn`, and `channel`.
-
-#![experimental]
-
-// Reexported core operators
-#[doc(no_inline)] pub use kinds::{Copy, Send, Sized, Sync};
-#[doc(no_inline)] pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
-#[doc(no_inline)] pub use ops::{BitAnd, BitOr, BitXor};
-#[doc(no_inline)] pub use ops::{Drop, Deref, DerefMut};
-#[doc(no_inline)] pub use ops::{Shl, Shr};
-#[doc(no_inline)] pub use ops::{Index, IndexMut};
-#[doc(no_inline)] pub use ops::{Slice, SliceMut};
-#[doc(no_inline)] pub use ops::{Fn, FnMut, FnOnce};
-
-// Reexported functions
-#[doc(no_inline)] pub use iter::range;
-#[doc(no_inline)] pub use mem::drop;
-#[doc(no_inline)] pub use str::from_str;
-
-// Reexported types and traits
-
-#[doc(no_inline)] pub use borrow::IntoCow;
-#[doc(no_inline)] pub use c_str::ToCStr;
-#[doc(no_inline)] pub use char::{Char, UnicodeChar};
-#[doc(no_inline)] pub use clone::Clone;
-#[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
-#[doc(no_inline)] pub use cmp::{Ordering, Equiv};
-#[doc(no_inline)] pub use cmp::Ordering::{Less, Equal, Greater};
-#[doc(no_inline)] pub use iter::{FromIterator, Extend, ExactSizeIterator};
-#[doc(no_inline)] pub use iter::{Iterator, IteratorExt, DoubleEndedIterator};
-#[doc(no_inline)] pub use iter::{DoubleEndedIteratorExt, CloneIteratorExt};
-#[doc(no_inline)] pub use iter::{RandomAccessIterator, IteratorCloneExt, IteratorPairExt};
-#[doc(no_inline)] pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator};
-#[doc(no_inline)] pub use num::{ToPrimitive, FromPrimitive};
-#[doc(no_inline)] pub use boxed::Box;
-#[doc(no_inline)] pub use option::Option;
-#[doc(no_inline)] pub use option::Option::{Some, None};
-#[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath};
-#[doc(no_inline)] pub use ptr::{PtrExt, MutPtrExt};
-#[doc(no_inline)] pub use result::Result;
-#[doc(no_inline)] pub use result::Result::{Ok, Err};
-#[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek, BufferPrelude};
-#[doc(no_inline)] pub use core::prelude::{Tuple1, Tuple2, Tuple3, Tuple4};
-#[doc(no_inline)] pub use core::prelude::{Tuple5, Tuple6, Tuple7, Tuple8};
-#[doc(no_inline)] pub use core::prelude::{Tuple9, Tuple10, Tuple11, Tuple12};
-#[doc(no_inline)] pub use str::{Str, StrExt};
-#[doc(no_inline)] pub use slice::AsSlice;
-#[doc(no_inline)] pub use slice::{SliceConcatExt, PartialEqSliceExt};
-#[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt};
-#[doc(no_inline)] pub use slice::{BoxedSliceExt};
-#[doc(no_inline)] pub use string::{IntoString, String, ToString};
-#[doc(no_inline)] pub use vec::Vec;
-
-// Reexported runtime types
-#[doc(no_inline)] pub use comm::{sync_channel, channel};
-#[doc(no_inline)] pub use comm::{SyncSender, Sender, Receiver};
-#[doc(no_inline)] pub use task::spawn;
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! The Rust prelude
+//!
+//! Because `std` is required by most serious Rust software, it is
+//! imported at the topmost level of every crate by default, as if the
+//! first line of each crate was
+//!
+//! ```ignore
+//! extern crate std;
+//! ```
+//!
+//! This means that the contents of std can be accessed from any context
+//! with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`,
+//! etc.
+//!
+//! Additionally, `std` contains a `prelude` module that reexports many of the
+//! most common traits, types and functions. The contents of the prelude are
+//! imported into every *module* by default. Implicitly, all modules behave as if
+//! they contained the following prologue:
+//!
+//! ```ignore
+//! use std::prelude::v1::*;
+//! ```
+//!
+//! The prelude is primarily concerned with exporting *traits* that are so
+//! pervasive that it would be obnoxious to import for every use, particularly
+//! those that define methods on primitive types.
+
+#[cfg(stage0)]
+pub use self::v1::*;
+
+#[stable]
+pub mod v1;
--- /dev/null
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! The first version of the prelude of the standard library.
+
+#![stable]
+
+// Reexported core operators
+#[stable] #[doc(no_inline)] pub use kinds::{Copy, Send, Sized, Sync};
+#[stable] #[doc(no_inline)] pub use ops::{Drop, Fn, FnMut, FnOnce};
+
+// Reexported functions
+#[stable] #[doc(no_inline)] pub use mem::drop;
+
+// Reexported types and traits
+
+#[stable] #[doc(no_inline)] pub use boxed::Box;
+#[stable] #[doc(no_inline)] pub use char::{Char, UnicodeChar};
+#[stable] #[doc(no_inline)] pub use clone::Clone;
+#[stable] #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
+#[stable] #[doc(no_inline)] pub use iter::CloneIteratorExt;
+#[stable] #[doc(no_inline)] pub use iter::DoubleEndedIterator;
+#[stable] #[doc(no_inline)] pub use iter::DoubleEndedIteratorExt;
+#[stable] #[doc(no_inline)] pub use iter::ExactSizeIterator;
+#[stable] #[doc(no_inline)] pub use iter::{Iterator, IteratorExt, Extend};
+#[stable] #[doc(no_inline)] pub use iter::{IteratorCloneExt, IteratorOrdExt};
+#[stable] #[doc(no_inline)] pub use iter::IteratorPairExt;
+#[stable] #[doc(no_inline)] pub use option::Option::{mod, Some, None};
+#[stable] #[doc(no_inline)] pub use ptr::{PtrExt, MutPtrExt};
+#[stable] #[doc(no_inline)] pub use result::Result::{mod, Ok, Err};
+#[stable] #[doc(no_inline)] pub use slice::AsSlice;
+#[stable] #[doc(no_inline)] pub use slice::{BoxedSliceExt, SliceExt};
+#[stable] #[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt};
+#[stable] #[doc(no_inline)] pub use slice::{PartialEqSliceExt, SliceConcatExt};
+#[stable] #[doc(no_inline)] pub use str::{Str, StrExt};
+#[stable] #[doc(no_inline)] pub use string::{String, ToString};
+#[stable] #[doc(no_inline)] pub use vec::Vec;
+
+// NB: remove when path reform lands
+#[doc(no_inline)] pub use path::{Path, GenericPath};
+// NB: remove when I/O reform lands
+#[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek, BufferPrelude};
+// NB: remove when range syntax lands
+#[doc(no_inline)] pub use iter::range;
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use super::{Rng, thread_rng, random, SeedableRng, StdRng, sample};
use iter::order;
#[cfg(test)]
mod bench {
extern crate test;
- use prelude::*;
+ use prelude::v1::*;
use self::test::Bencher;
use super::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N};
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
- use super::OsRng;
+ use comm::channel;
use rand::Rng;
+ use super::OsRng;
use thread::Thread;
#[test]
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use super::ReaderRng;
use io::MemReader;
target_os = "freebsd",
target_os = "dragonfly"))]
mod imp {
- use prelude::*;
+ use prelude::v1::*;
use mem;
use slice;
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use finally::Finally;
use super::*;
#![allow(non_camel_case_types)]
-use prelude::*;
+use prelude::v1::*;
use os;
use sync::atomic;
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use sys_common;
macro_rules! t { ($a:expr, $b:expr) => ({
let mut m = Vec::new();
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use sync::Arc;
use super::Exclusive;
use task;
#![allow(dead_code)]
-use os;
-use thunk::Thunk;
use kinds::Send;
-use thread::Thread;
use ops::FnOnce;
use sys;
-use sys_common;
-use sys_common::thread_info::{mod, NewThread};
+use thunk::Thunk;
// Reexport some of our utilities which are expected by other crates.
pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};
#[cfg(not(test))]
#[lang = "start"]
fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int {
+ use prelude::v1::*;
+
use mem;
- use prelude::*;
+ use os;
use rt;
+ use sys_common::thread_info::{mod, NewThread};
+ use sys_common;
+ use thread::Thread;
let something_around_the_top_of_the_stack = 1;
let addr = &something_around_the_top_of_the_stack as *const int;
#[cfg(test)]
mod test {
use super::*;
- use prelude::*;
+ use prelude::v1::*;
use task;
use rt::unwind;
//!
//! Currently Rust uses unwind runtime provided by libgcc.
-use prelude::*;
+use prelude::v1::*;
use any::Any;
use cell::Cell;
//
// ignore-lexer-test FIXME #15677
-use prelude::*;
+use prelude::v1::*;
use cmp;
use fmt;
use intrinsics;
-use libc::uintptr_t;
-use libc;
+use libc::{mod, uintptr_t};
use os;
use slice;
use str;
#[cfg(test)]
mod test {
- use prelude::{Some, None};
+ use prelude::v1::*;
use super::*;
#[test]
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use sync::{Arc, Barrier};
- use comm::Empty;
+ use comm::{channel, Empty};
+ use thread::Thread;
#[test]
fn test_barrier() {
for _ in range(0u, 9) {
let c = barrier.clone();
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
c.wait();
tx.send(true);
- });
+ }).detach();
}
// At this point, all spawned tasks should be blocked,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use sync::atomic::{mod, AtomicUint};
use sync::poison::{mod, LockResult};
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
- use time::Duration;
+ use comm::channel;
use super::{StaticCondvar, CONDVAR_INIT};
use sync::{StaticMutex, MUTEX_INIT, Condvar, Mutex, Arc};
+ use thread::Thread;
+ use time::Duration;
#[test]
fn smoke() {
static C: StaticCondvar = CONDVAR_INIT;
static M: StaticMutex = MUTEX_INIT;
- let g = M.lock().unwrap();
- spawn(move|| {
+ let mut g = M.lock().unwrap();
+ let _t = Thread::spawn(move|| {
let _g = M.lock().unwrap();
C.notify_one();
});
for _ in range(0, N) {
let data = data.clone();
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
let &(ref lock, ref cond) = &*data;
let mut cnt = lock.lock().unwrap();
*cnt += 1;
cnt = cond.wait(cnt).unwrap();
}
tx.send(());
- });
+ }).detach();
}
drop(tx);
let g = M.lock().unwrap();
let (g, success) = C.wait_timeout(g, Duration::nanoseconds(1000)).unwrap();
assert!(!success);
- spawn(move|| {
+ let _t = Thread::spawn(move || {
let _g = M.lock().unwrap();
C.notify_one();
});
static C: StaticCondvar = CONDVAR_INIT;
let mut g = M1.lock().unwrap();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _g = M1.lock().unwrap();
C.notify_one();
});
drop(g);
C.wait(M2.lock().unwrap()).unwrap();
-
}
}
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
+ use comm::channel;
use sync::Future;
- use task;
+ use thread::Thread;
#[test]
fn test_from_value() {
let expected = "schlorf";
let (tx, rx) = channel();
let f = Future::spawn(move|| { expected });
- task::spawn(move|| {
+ let _t = Thread::spawn(move|| {
let mut f = f;
tx.send(f.get());
});
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use cell::UnsafeCell;
use kinds::marker;
+use ops::{Deref, DerefMut};
use sync::poison::{mod, TryLockError, TryLockResult, LockResult};
use sys_common::mutex as sys;
/// ```rust
/// use std::sync::{Arc, Mutex};
/// use std::thread::Thread;
+/// use std::comm::channel;
+///
/// const N: uint = 10;
///
/// // Spawn a few threads to increment a shared variable (non-atomically), and
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
- use thread::Thread;
+ use comm::channel;
use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar};
+ use thread::Thread;
struct Packet<T>(Arc<(Mutex<T>, Condvar)>);
let (tx, rx) = channel();
for _ in range(0, K) {
let tx2 = tx.clone();
- spawn(move|| { inc(); tx2.send(()); });
+ Thread::spawn(move|| { inc(); tx2.send(()); }).detach();
let tx2 = tx.clone();
- spawn(move|| { inc(); tx2.send(()); });
+ Thread::spawn(move|| { inc(); tx2.send(()); }).detach();
}
drop(tx);
let packet = Packet(Arc::new((Mutex::new(false), Condvar::new())));
let packet2 = Packet(packet.0.clone());
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
// wait until parent gets in
rx.recv();
let &(ref lock, ref cvar) = &*packet2.0;
let packet2 = Packet(packet.0.clone());
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move || -> () {
rx.recv();
let &(ref lock, ref cvar) = &*packet2.0;
let _g = lock.lock().unwrap();
let arc = Arc::new(Mutex::new(1i));
let arc2 = Arc::new(Mutex::new(arc));
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let lock = arc2.lock().unwrap();
- let lock2 = lock.deref().lock().unwrap();
+ let lock2 = lock.lock().unwrap();
assert_eq!(*lock2, 1);
tx.send(());
});
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use thread::Thread;
use super::{ONCE_INIT, Once};
+ use comm::channel;
#[test]
fn smoke_once() {
let (tx, rx) = channel();
for _ in range(0u, 10) {
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
for _ in range(0u, 4) { Thread::yield_now() }
unsafe {
O.doit(|| {
assert!(run);
}
tx.send(());
- });
+ }).detach();
}
unsafe {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use cell::UnsafeCell;
use error::FromError;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use cell::UnsafeCell;
use kinds::marker;
+use ops::{Deref, DerefMut};
use sync::poison::{mod, LockResult, TryLockError, TryLockResult};
use sys_common::rwlock as sys;
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use rand::{mod, Rng};
+ use comm::channel;
use thread::Thread;
use sync::{Arc, RWLock, StaticRWLock, RWLOCK_INIT};
let (tx, rx) = channel::<()>();
for _ in range(0, N) {
let tx = tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut rng = rand::thread_rng();
for _ in range(0, M) {
if rng.gen_weighted_bool(N) {
}
}
drop(tx);
- });
+ }).detach();
}
drop(tx);
let _ = rx.recv_opt();
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use sync::Arc;
use super::Semaphore;
+ use comm::channel;
+ use thread::Thread;
#[test]
fn test_sem_acquire_release() {
fn test_sem_as_mutex() {
let s = Arc::new(Semaphore::new(1));
let s2 = s.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _g = s2.access();
});
let _g = s.access();
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
s2.acquire();
tx.send(());
});
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
s2.release();
let _ = rx.recv();
});
let s2 = s.clone();
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
let _g = s2.access();
let _ = rx2.recv();
tx1.send(());
let (tx, rx) = channel();
{
let _g = s.access();
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(());
drop(s2.access());
tx.send(());
- });
+ }).detach();
rx.recv(); // wait for child to come alive
}
rx.recv(); // wait for child to be done
/// # Example
///
/// ```rust
-/// # use std::sync::TaskPool;
-/// # use std::iter::AdditiveIterator;
+/// use std::sync::TaskPool;
+/// use std::iter::AdditiveIterator;
+/// use std::comm::channel;
///
/// let pool = TaskPool::new(4u);
///
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
use super::*;
+ use comm::channel;
const TEST_TASKS: uint = 4u;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use io::IoResult;
//! can be created in the future and there must be no active timers at that
//! time.
-use prelude::*;
+use prelude::v1::*;
use cell::UnsafeCell;
+use comm::{channel, Sender, Receiver};
use mem;
-use sync::{StaticMutex, StaticCondvar};
use rt;
+use sync::{StaticMutex, StaticCondvar};
use sys::helper_signal;
use thread::Thread;
#![allow(dead_code)]
use io::{mod, IoError, IoResult};
-use prelude::*;
+use prelude::v1::*;
use sys::{last_error, retry};
use c_str::CString;
use num::Int;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use prelude::v1::*;
use self::SocketStatus::*;
use self::InAddr::*;
-use alloc::arc::Arc;
+use c_str::ToCStr;
+use io::net::addrinfo;
+use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr};
+use io::{IoResult, IoError};
use libc::{mod, c_char, c_int};
use c_str::CString;
use mem;
use num::Int;
use ptr::{mod, null, null_mut};
-use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr};
-use io::net::addrinfo;
-use io::{IoResult, IoError};
use sys::{mod, retry, c, sock_t, last_error, last_net_error, last_gai_error, close_sock,
wrlen, msglen_t, os, wouldblock, set_nonblocking, timer, ms_to_timeval,
decode_error_detailed};
-use sync::{Mutex, MutexGuard};
+use sync::{Arc, Mutex, MutexGuard};
use sys_common::{mod, keep_going, short_write, timeout};
-use prelude::*;
use cmp;
use io;
#![allow(non_camel_case_types)]
-use prelude::*;
+use prelude::v1::*;
use sync::atomic::{mod, AtomicUint};
use sync::{Mutex, Once, ONCE_INIT};
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
use super::{Key, StaticKey, INIT_INNER};
fn assert_sync<T: Sync>() {}
//! Blocking posix-based file I/O
-use libc::{mod, c_int, c_void};
-use c_str::CString;
-use mem;
-use io;
-
-use prelude::*;
+use prelude::v1::*;
+use c_str::{CString, ToCStr};
use io::{FilePermission, Write, UnstableFileStat, Open, FileAccess, FileMode};
use io::{IoResult, FileStat, SeekStyle};
use io::{Read, Truncate, SeekCur, SeekSet, ReadWrite, SeekEnd, Append};
+use io;
+use libc::{mod, c_int, c_void};
+use mem;
use sys::retry;
use sys_common::{keep_going, eof, mkerr_libc};
use super::FileDesc;
use libc;
use os;
- use prelude::*;
+ use prelude::v1::*;
#[cfg_attr(target_os = "freebsd", ignore)] // hmm, maybe pipes have a tiny buffer
#[test]
use num;
use num::{Int, SignedInt};
-use prelude::*;
+use prelude::v1::*;
use io::{mod, IoResult, IoError};
use sys_common::mkerr_libc;
//! Implementation of `std::os` functionality for unix systems
-use prelude::*;
+use prelude::v1::*;
+use c_str::ToCStr;
use error::{FromError, Error};
use fmt;
use io::{IoError, IoResult};
use libc::{mod, c_int, c_char, c_void};
-use path::BytesContainer;
+use os;
+use path::{BytesContainer};
use ptr;
use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
use sys::fs::FileDesc;
-use os;
use os::TMPBUF_SZ;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use alloc::arc::Arc;
+use prelude::v1::*;
+
use libc;
use c_str::CString;
use mem;
-use sync::{atomic, Mutex};
+use sync::{atomic, Arc, Mutex};
use io::{mod, IoResult, IoError};
-use prelude::*;
use sys::{mod, timer, retry, c, set_nonblocking, wouldblock};
use sys::fs::{fd_t, FileDesc};
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+
+use prelude::v1::*;
use self::Req::*;
-use libc::{mod, pid_t, c_void, c_int};
-use c_str::CString;
+use c_str::{CString, ToCStr};
+use collections;
+use comm::{channel, Sender, Receiver};
+use hash::Hash;
+use io::process::{ProcessExit, ExitStatus, ExitSignal};
use io::{mod, IoResult, IoError, EndOfFile};
+use libc::{mod, pid_t, c_void, c_int};
use mem;
use os;
-use ptr;
-use prelude::*;
-use io::process::{ProcessExit, ExitStatus, ExitSignal};
-use collections;
use path::BytesContainer;
-use hash::Hash;
-
-use sys::{mod, retry, c, wouldblock, set_nonblocking, ms_to_timeval};
+use ptr;
use sys::fs::FileDesc;
+use sys::{mod, retry, c, wouldblock, set_nonblocking, ms_to_timeval};
use sys_common::helper_thread::Helper;
use sys_common::{AsInner, mkerr_libc, timeout};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use prelude::v1::*;
+
use io::net::ip;
use io::IoResult;
use libc;
use mem;
use ptr;
-use prelude::*;
use super::{last_error, last_net_error, retry, sock_t};
use sync::{Arc, atomic};
use sys::fs::FileDesc;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use libc::c_int;
pub type Key = pthread_key_t;
//!
//! Note that all time units in this file are in *milliseconds*.
+use prelude::v1::*;
use self::Req::*;
+use comm::{mod, channel, Sender, Receiver};
+use io::IoResult;
use libc;
use mem;
use os;
use ptr;
use sync::atomic;
-use comm;
use sys::c;
use sys::fs::FileDesc;
use sys_common::helper_thread::Helper;
-use prelude::*;
-use io::IoResult;
helper_init! { static HELPER: Helper<Req> }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use prelude::v1::*;
+
use sys::fs::FileDesc;
-use prelude::*;
use libc::{mod, c_int};
use io::{mod, IoResult, IoError};
use sys_common;
#![allow(non_camel_case_types)]
use libc;
-use prelude::*;
+use prelude::v1::*;
pub const WSADESCRIPTION_LEN: uint = 256;
pub const WSASYS_STATUS_LEN: uint = 128;
pub mod compat {
use intrinsics::{atomic_store_relaxed, transmute};
use libc::types::os::arch::extra::{LPCWSTR, HMODULE, LPCSTR, LPVOID};
- use prelude::*;
+ use prelude::v1::*;
+
+ use c_str::ToCStr;
extern "system" {
fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
use str;
use io;
-use prelude::*;
+use prelude::v1::*;
use sys;
use sys::os;
use sys_common::{keep_going, eof, mkerr_libc};
extern crate libc;
+use prelude::v1::*;
+
use num;
use mem;
-use prelude::*;
use io::{mod, IoResult, IoError};
use sync::{Once, ONCE_INIT};
+use comm::Sender;
macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => (
static $name: Helper<$m> = Helper {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use sync::atomic;
use alloc::{mod, heap};
// FIXME: move various extern bindings from here into liblibc or
// something similar
-use prelude::*;
+use prelude::v1::*;
use fmt;
use io::{IoResult, IoError};
//! the test suite passing (the suite is in libstd), and that's good enough for
//! me!
-use alloc::arc::Arc;
+use prelude::v1::*;
+
use libc;
use c_str::CString;
use mem;
use ptr;
-use sync::{atomic, Mutex};
+use sync::{atomic, Arc, Mutex};
use io::{mod, IoError, IoResult};
-use prelude::*;
use sys_common::{mod, eof};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use prelude::v1::*;
+
use libc::{pid_t, c_void, c_int};
use libc;
-use c_str::CString;
+use c_str::{CString, ToCStr};
use io;
use mem;
use os;
use ptr;
-use prelude::*;
use io::process::{ProcessExit, ExitStatus, ExitSignal};
use collections;
use path::BytesContainer;
#[test]
fn test_make_command_line() {
- use prelude::*;
+ use prelude::v1::*;
use str;
use c_str::CString;
use super::make_command_line;
use libc;
use mem;
use ptr;
-use prelude::*;
+use prelude::v1::*;
use super::{last_error, last_net_error, retry, sock_t};
use sync::{Arc, atomic};
use sys::fs::FileDesc;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use prelude::*;
+use prelude::v1::*;
use libc::types::os::arch::extra::{DWORD, LPVOID, BOOL};
//! the other two implementations of timers with nothing *that* new showing up.
use self::Req::*;
+use prelude::v1::*;
use libc;
use ptr;
use comm;
+use comm::{channel, Sender, Receiver};
+use io::IoResult;
use sys::c;
use sys::fs::FileDesc;
use sys_common::helper_thread::Helper;
-use prelude::*;
-use io::IoResult;
helper_init! { static HELPER: Helper<Req> }
//! wrapper that performs encoding/decoding, this implementation should switch
//! to working in raw UTF-16, with such a wrapper around it.
-use super::c::{ReadConsoleW, WriteConsoleW, GetConsoleMode, SetConsoleMode};
-use super::c::{ERROR_ILLEGAL_CHARACTER};
-use super::c::{ENABLE_ECHO_INPUT, ENABLE_EXTENDED_FLAGS};
-use super::c::{ENABLE_INSERT_MODE, ENABLE_LINE_INPUT};
-use super::c::{ENABLE_PROCESSED_INPUT, ENABLE_QUICK_EDIT_MODE};
-use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID};
-use libc::{get_osfhandle, CloseHandle};
-use libc::types::os::arch::extra::LPCVOID;
+use prelude::v1::*;
+
use io::{mod, IoError, IoResult, MemReader};
use iter::repeat;
-use prelude::*;
+use libc::types::os::arch::extra::LPCVOID;
+use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID};
+use libc::{get_osfhandle, CloseHandle};
use ptr;
use str::from_utf8;
+use super::c::{ENABLE_ECHO_INPUT, ENABLE_EXTENDED_FLAGS};
+use super::c::{ENABLE_INSERT_MODE, ENABLE_LINE_INPUT};
+use super::c::{ENABLE_PROCESSED_INPUT, ENABLE_QUICK_EDIT_MODE};
+use super::c::{ERROR_ILLEGAL_CHARACTER};
+use super::c::{ReadConsoleW, WriteConsoleW, GetConsoleMode, SetConsoleMode};
fn invalid_encoding() -> IoError {
IoError {
#[cfg(test)]
mod test {
- use prelude::*;
+ use prelude::v1::*;
+
use any::{Any, AnyRefExt};
use boxed::BoxAny;
+ use comm::{channel, Sender};
use result;
use std::io::{ChanReader, ChanWriter};
- use thunk::Thunk;
use super::{Thread, Builder};
+ use thunk::Thunk;
// !!! These tests are dangerous. If something is buggy, they will hang, !!!
// !!! instead of exiting cleanly. This might wedge the buildbots. !!!
#![macro_escape]
#![experimental]
-use prelude::*;
+use prelude::v1::*;
use cell::UnsafeCell;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod imp {
- use prelude::*;
+ use prelude::v1::*;
use cell::UnsafeCell;
use intrinsics;
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
mod imp {
- use prelude::*;
+ use prelude::v1::*;
use cell::UnsafeCell;
use mem;
#[cfg(test)]
mod tests {
- use prelude::*;
+ use prelude::v1::*;
+ use comm::{channel, Sender};
use cell::UnsafeCell;
use thread::Thread;
*f.get() = 2;
});
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
FOO.with(|f| unsafe {
assert_eq!(*f.get(), 1);
});
});
let (tx, rx) = channel();
- spawn(move|| unsafe {
+ let _t = Thread::spawn(move|| unsafe {
let mut tx = Some(tx);
FOO.with(|f| {
*f.get() = Some(Foo(tx.take().unwrap()));
Thread::spawn(move|| {
drop(S1);
- }).join();
+ }).join().ok().unwrap();
}
#[test]
Thread::spawn(move|| unsafe {
K1.with(|s| *s.get() = Some(S1));
- }).join();
+ }).join().ok().unwrap();
}
#[test]
}
let (tx, rx) = channel();
- spawn(move|| unsafe {
+ let _t = Thread::spawn(move|| unsafe {
let mut tx = Some(tx);
K1.with(|s| *s.get() = Some(S1(tx.take().unwrap())));
});
#[cfg(test)]
mod dynamic_tests {
- use prelude::*;
+ use prelude::v1::*;
use cell::RefCell;
use collections::HashMap;
#![macro_escape]
-use prelude::*;
+use prelude::v1::*;
// macro hygiene sure would be nice, wouldn't it?
#[doc(hidden)] pub use self::imp::KeyInner;
#[cfg(test)]
mod tests {
use cell::Cell;
- use prelude::*;
+ use prelude::v1::*;
scoped_thread_local!(static FOO: uint);
//!
//! # Examples
//!
-//! Using methods:
+//! Using fields:
//!
//! ```
//! #[allow(deprecated)]
//! # fn main() {
//! let pair = ("pi", 3.14f64);
-//! assert_eq!(pair.val0(), "pi");
-//! assert_eq!(pair.val1(), 3.14f64);
+//! assert_eq!(pair.0, "pi");
+//! assert_eq!(pair.1, 3.14f64);
//! # }
//! ```
//!
//
// ignore-lexer-test FIXME #15679
-//! The CodeMap tracks all the source code used within a single crate, mapping from integer byte
-//! positions to the original source code location. Each bit of source parsed during crate parsing
-//! (typically files, in-memory strings, or various bits of macro expansion) cover a continuous
-//! range of bytes in the CodeMap and are represented by FileMaps. Byte positions are stored in
-//! `spans` and used pervasively in the compiler. They are absolute positions within the CodeMap,
-//! which upon request can be converted to line and column information, source code snippets, etc.
+//! The CodeMap tracks all the source code used within a single crate, mapping
+//! from integer byte positions to the original source code location. Each bit
+//! of source parsed during crate parsing (typically files, in-memory strings,
+//! or various bits of macro expansion) cover a continuous range of bytes in the
+//! CodeMap and are represented by FileMaps. Byte positions are stored in
+//! `spans` and used pervasively in the compiler. They are absolute positions
+//! within the CodeMap, which upon request can be converted to line and column
+//! information, source code snippets, etc.
pub use self::MacroFormat::*;
-use serialize::{Encodable, Decodable, Encoder, Decoder};
use std::cell::RefCell;
+use std::num::ToPrimitive;
+use std::ops::{Add, Sub};
use std::rc::Rc;
+
use libc::c_uint;
+use serialize::{Encodable, Decodable, Encoder, Decoder};
pub trait Pos {
fn from_uint(n: uint) -> Self;
use ext::build::AstBuilder;
use std::ascii::AsciiExt;
-
pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
tts: &[ast::TokenTree])
impl<T: ToTokens> ToTokens for Vec<T> {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
- let a = self.iter().flat_map(|t| t.to_tokens(cx).into_iter());
- FromIterator::from_iter(a)
+ self.iter().flat_map(|t| t.to_tokens(cx).into_iter()).collect()
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::fmt;
use std::default::Default;
+use std::fmt;
+use std::iter::FromIterator;
+use std::ops::Deref;
use std::vec;
use serialize::{Encodable, Decodable, Encoder, Decoder};
use parse::token;
use parse::token::{str_to_ident};
+use std::borrow::IntoCow;
use std::char;
use std::fmt;
use std::mem::replace;
pub fn nextnextch(&self) -> Option<char> {
let offset = self.byte_offset(self.pos).to_uint();
- let s = self.filemap.deref().src[];
+ let s = self.filemap.src.as_slice();
if offset >= s.len() { return None }
let str::CharRange { next, .. } = s.char_range_at(offset);
if next < s.len() {
use std::collections::HashSet;
use std::io::fs::PathExtensions;
+use std::iter;
use std::mem;
use std::num::Float;
use std::rc::Rc;
-use std::iter;
use std::slice;
+use std::str::from_str;
bitflags! {
flags Restrictions: u8 {
use util::interner;
use serialize::{Decodable, Decoder, Encodable, Encoder};
+use std::cmp::Equiv;
use std::fmt;
use std::mem;
+use std::ops::Deref;
use std::path::BytesContainer;
use std::rc::Rc;
//! The AST pointer
//!
-//! Provides `P<T>`, a frozen owned smart pointer, as a replacement for `@T` in the AST.
+//! Provides `P<T>`, a frozen owned smart pointer, as a replacement for `@T` in
+//! the AST.
//!
//! # Motivations and benefits
//!
-//! * **Identity**: sharing AST nodes is problematic for the various analysis passes
-//! (e.g. one may be able to bypass the borrow checker with a shared `ExprAddrOf`
-//! node taking a mutable borrow). The only reason `@T` in the AST hasn't caused
-//! issues is because of inefficient folding passes which would always deduplicate
-//! any such shared nodes. Even if the AST were to switch to an arena, this would
-//! still hold, i.e. it couldn't use `&'a T`, but rather a wrapper like `P<'a, T>`.
+//! * **Identity**: sharing AST nodes is problematic for the various analysis
+//! passes (e.g. one may be able to bypass the borrow checker with a shared
+//! `ExprAddrOf` node taking a mutable borrow). The only reason `@T` in the
+//! AST hasn't caused issues is because of inefficient folding passes which
+//! would always deduplicate any such shared nodes. Even if the AST were to
+//! switch to an arena, this would still hold, i.e. it couldn't use `&'a T`,
+//! but rather a wrapper like `P<'a, T>`.
//!
//! * **Immutability**: `P<T>` disallows mutating its inner `T`, unlike `Box<T>`
//! (unless it contains an `Unsafe` interior, but that may be denied later).
//! implementation changes (using a special thread-local heap, for example).
//! Moreover, a switch to, e.g. `P<'a, T>` would be easy and mostly automated.
-use std::fmt;
-use std::fmt::Show;
+use std::fmt::{mod, Show};
use std::hash::Hash;
+use std::ops::Deref;
use std::ptr;
use serialize::{Encodable, Decodable, Encoder, Decoder};
let prelude_path = ast::Path {
span: DUMMY_SP,
global: false,
- segments: vec!(
+ segments: vec![
ast::PathSegment {
identifier: token::str_to_ident("std"),
parameters: ast::PathParameters::none(),
ast::PathSegment {
identifier: token::str_to_ident("prelude"),
parameters: ast::PathParameters::none(),
- }),
+ },
+ ast::PathSegment {
+ identifier: token::str_to_ident("v1"),
+ parameters: ast::PathParameters::none(),
+ },
+ ],
};
let (crates, uses): (Vec<_>, _) = view_items.iter().cloned().partition(|x| {
use ast::Name;
use std::borrow::BorrowFrom;
-use std::collections::HashMap;
use std::cell::RefCell;
+use std::cmp::Ordering;
+use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;
+use std::ops::Deref;
use std::rc::Rc;
pub struct Interner<T> {
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+
use self::SmallVectorRepr::*;
use self::IntoIterRepr::*;
+use std::iter::FromIterator;
use std::mem;
use std::slice;
use std::vec;
use self::NamePadding::*;
use self::OutputLocation::*;
-use std::any::{Any, AnyRefExt};
-use std::collections::BTreeMap;
use stats::Stats;
use getopts::{OptGroup, optflag, optopt};
use regex::Regex;
use term::Terminal;
use term::color::{Color, RED, YELLOW, GREEN, CYAN};
+use std::any::{Any, AnyRefExt};
use std::cmp;
+use std::collections::BTreeMap;
+use std::comm::{channel, Sender};
use std::f64;
use std::fmt::Show;
use std::fmt;
use std::iter::repeat;
use std::num::{Float, FloatMath, Int};
use std::os;
-use std::str::FromStr;
-use std::string::String;
+use std::str::{FromStr, from_str};
use std::thread::{mod, Thread};
-use std::time::Duration;
use std::thunk::{Thunk, Invoke};
+use std::time::Duration;
// to be used by rustc to compile tests in libtest
pub mod test {
StaticTestName, DynTestName, DynTestFn, ShouldFail};
use std::io::TempDir;
use std::thunk::Thunk;
+ use std::comm::channel;
#[test]
pub fn do_not_run_ignored_tests() {
#![allow(missing_docs)]
-use std::collections::hash_map;
+use std::cmp::Ordering::{mod, Less, Greater, Equal};
use std::collections::hash_map::Entry::{Occupied, Vacant};
+use std::collections::hash_map;
use std::fmt::Show;
use std::hash::Hash;
use std::io;
use std::mem;
-use std::num::{Float, FloatMath};
+use std::num::{Float, FloatMath, FromPrimitive};
fn local_cmp<T:Float>(x: T, y: T) -> Ordering {
// arbitrarily decide that NaNs are larger than everything.
pub use self::ParseError::*;
use self::Fmt::*;
-use std::fmt::Show;
-use std::fmt;
+use std::fmt::{mod, Show};
use std::num::SignedInt;
-use std::string::String;
+use std::ops::{Add, Sub};
use std::time::Duration;
static NSEC_PER_SEC: i32 = 1_000_000_000_i32;
#[cfg(windows)]
fn set_time_zone() {
use libc;
+ use std::c_str::ToCStr;
// Windows crt doesn't see any environment variable set by
// `SetEnvironmentVariable`, which `os::setenv` internally uses.
// It is why we use `putenv` here.
// except according to those terms.
use std::task;
+use std::comm::{Receiver, channel};
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
let (tx, rx) = channel();
#![crate_type = "lib"]
use std::int;
+use std::str::from_str;
pub trait read {
fn readMaybe(s: String) -> Option<Self>;
// except according to those terms.
use std::cmp::PartialEq;
+use std::ops::{Add, Sub, Mul};
pub trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone {
}
#![feature(unboxed_closures)]
+use std::ops::Add;
+
#[inline]
pub fn has_closures() -> uint {
let x = 1u;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::os;
use std::rand::{Rng, IsaacRng, SeedableRng};
+use std::str::from_str;
use std::time::Duration;
use std::uint;
extern crate collections;
extern crate rand;
+use std::collections::BTreeSet;
use std::collections::BitvSet;
use std::collections::HashSet;
-use std::collections::BTreeSet;
use std::hash::Hash;
use std::os;
+use std::str::from_str;
use std::time::Duration;
use std::uint;
// except according to those terms.
use std::os;
+use std::str::from_str;
use std::uint;
fn main() {
// different scalability characteristics compared to the select
// version.
+use std::comm::{channel, Sender, Receiver};
use std::comm;
use std::os;
+use std::str::from_str;
use std::thread::Thread;
use std::time::Duration;
use std::uint;
//
// I *think* it's the same, more or less.
+use std::comm::{channel, Sender, Receiver};
use std::os;
+use std::str::from_str;
use std::thread::Thread;
use std::time::Duration;
use std::uint;
// ignore-lexer-test FIXME #15679
use std::os;
+use std::str::from_str;
use std::sync::{Arc, Future, Mutex, Condvar};
use std::time::Duration;
use std::uint;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
use std::os;
+use std::str::from_str;
+use std::thread::Thread;
use std::uint;
// This is a simple bench that creates M pairs of tasks. These
// Create a stream B->A
let (btx, brx) = channel::<()>();
- spawn(move|| {
+ Thread::spawn(move|| {
let (tx, rx) = (atx, brx);
for _ in range(0, n) {
tx.send(());
rx.recv();
}
- });
+ }).detach();
- spawn(move|| {
+ Thread::spawn(move|| {
let (tx, rx) = (btx, arx);
for _ in range(0, n) {
rx.recv();
tx.send(());
}
- });
+ }).detach();
}
for _ in range(0, m) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
use std::os;
+use std::str::from_str;
+use std::thread::Thread;
use std::uint;
// A simple implementation of parfib. One subtree is found in a new
}
let (tx, rx) = channel();
- spawn(move|| {
+ Thread::spawn(move|| {
tx.send(parfib(n-1));
- });
+ }).detach();
let m2 = parfib(n-2);
return (rx.recv() + m2);
}
// except according to those terms.
use std::os;
+use std::str::from_str;
fn ack(m: int, n: int) -> int {
if m == 0 {
extern crate arena;
use std::iter::range_step;
+use std::str::from_str;
use std::sync::Future;
+
use arena::TypedArena;
enum Tree<'a> {
// no-pretty-expanded
use self::Color::{Red, Yellow, Blue};
-use std::string::String;
+use std::comm::{channel, Sender, Receiver};
use std::fmt;
+use std::str::from_str;
+use std::thread::Thread;
fn print_complements() {
let all = [Blue, Red, Yellow];
let to_rendezvous = to_rendezvous.clone();
let to_rendezvous_log = to_rendezvous_log.clone();
let (to_creature, from_rendezvous) = channel();
- spawn(move|| {
+ Thread::spawn(move|| {
creature(ii,
col,
from_rendezvous,
to_rendezvous,
to_rendezvous_log);
- });
+ }).detach();
to_creature
}).collect();
#![feature(slicing_syntax)]
-use std::{cmp, iter, mem};
+use std::str::from_str;
use std::sync::Future;
+use std::{cmp, iter, mem};
fn rotate(x: &mut [i32]) {
let mut prev = x[0];
use std::io::{stdout, IoResult};
use std::os;
use std::slice::bytes::copy_memory;
+use std::str::from_str;
const LINE_LEN: uint = 60;
const LOOKUP_SIZE: uint = 4 * 1024;
#![feature(slicing_syntax)]
-use std::io;
-use std::io::{BufferedWriter, File};
use std::cmp::min;
+use std::io::{BufferedWriter, File};
+use std::io;
use std::num::Float;
use std::os;
+use std::str::from_str;
const LINE_LENGTH: uint = 60;
const IM: u32 = 139968;
// except according to those terms.
use std::os;
+use std::str::from_str;
fn fib(n: int) -> int {
if n < 2 {
extern crate collections;
use std::ascii::{AsciiExt, OwnedAsciiExt};
+use std::cmp::Ordering::{mod, Less, Greater, Equal};
use std::collections::HashMap;
+use std::comm::{channel, Sender, Receiver};
use std::mem::replace;
use std::num::Float;
use std::option;
use std::os;
-use std::string::String;
+use std::string::IntoString;
+use std::thread::Thread;
fn f64_cmp(x: f64, y: f64) -> Ordering {
// arbitrarily decide that NaNs are larger than everything.
let (to_child, from_parent) = channel();
- spawn(move|| {
+ Thread::spawn(move|| {
make_sequence_processor(sz, &from_parent, &to_parent_);
- });
+ }).detach();
to_child
}).collect::<Vec<Sender<Vec<u8> >> >();
#![feature(slicing_syntax)]
use std::ascii::OwnedAsciiExt;
-use std::string::String;
use std::slice;
use std::sync::{Arc, Future};
use std::io;
use std::os;
use std::simd::f64x2;
+use std::str::from_str;
use std::sync::{Arc, Future};
const ITER: int = 50;
// no-pretty-expanded FIXME #15189
+use std::comm::channel;
use std::sync::Arc;
+use std::thread::Thread;
//
// Utilities.
let masks = masks.clone();
let tx = tx.clone();
let m = *m;
- spawn(move|| {
+ Thread::spawn(move|| {
let mut data = Data::new();
search(&*masks, m, 1, List::Cons(m, &List::Nil), &mut data);
tx.send(data);
- });
+ }).detach();
}
// collecting the results
// OF THE POSSIBILITY OF SUCH DAMAGE.
use std::num::Float;
+use std::str::from_str;
const PI: f64 = 3.141592653589793;
const SOLAR_MASS: f64 = 4.0 * PI * PI;
extern crate getopts;
+use std::comm::{channel, Sender};
use std::os;
use std::result::Result::{Ok, Err};
+use std::str::from_str;
use std::thread::Thread;
use std::time::Duration;
extern crate libc;
use std::io::stdio::{stdin_raw, stdout_raw};
+use std::io::{IoResult, EndOfFile};
use std::num::{div_rem};
use std::ptr::{copy_memory, Unique};
-use std::io::{IoResult, EndOfFile};
+use std::thread::Thread;
struct Tables {
table8: [u8;1 << 8],
fn parallel<'a, I, T, F>(mut iter: I, f: F)
where T: 'a+Send + Sync,
I: Iterator<&'a mut [T]>,
- F: Fn(&'a mut [T]) + Sync {
+ F: Fn(&mut [T]) + Sync {
use std::mem;
use std::raw::Repr;
- let (tx, rx) = channel();
- for chunk in iter {
- let tx = tx.clone();
-
+ iter.map(|chunk| {
// Need to convert `f` and `chunk` to something that can cross the task
// boundary.
let f = Racy(&f as *const F as *const uint);
let raw = Racy(chunk.repr());
- spawn(move|| {
+ Thread::spawn(move|| {
let f = f.0 as *const F;
unsafe { (*f)(mem::transmute(raw.0)) }
- drop(tx)
- });
- }
- drop(tx);
- for () in rx.iter() {}
+ })
+ }).collect::<Vec<_>>();
}
fn main() {
#![feature(unboxed_closures)]
use std::iter::AdditiveIterator;
+use std::thread::Thread;
use std::mem;
use std::num::Float;
use std::os;
use std::raw::Repr;
use std::simd::f64x2;
+use std::str::from_str;
fn main() {
let args = os::args();
}
fn mult_Av(v: &[f64], out: &mut [f64]) {
- parallel(out, |&: start, out| mult(v, out, start, |i, j| A(i, j)));
+ parallel(out, |start, out| mult(v, out, start, |i, j| A(i, j)));
}
fn mult_Atv(v: &[f64], out: &mut [f64]) {
- parallel(out, |&: start, out| mult(v, out, start, |i, j| A(j, i)));
+ parallel(out, |start, out| mult(v, out, start, |i, j| A(j, i)));
}
-fn mult(v: &[f64], out: &mut [f64], start: uint, a: |uint, uint| -> f64) {
+fn mult<F>(v: &[f64], out: &mut [f64], start: uint, a: F)
+ where F: Fn(uint, uint) -> f64 {
for (i, slot) in out.iter_mut().enumerate().map(|(i, s)| (i + start, s)) {
let mut sum = f64x2(0.0, 0.0);
for (j, chunk) in v.chunks(2).enumerate().map(|(j, s)| (2 * j, s)) {
// Executes a closure in parallel over the given mutable slice. The closure `f`
// is run in parallel and yielded the starting index within `v` as well as a
// sub-slice of `v`.
-fn parallel<'a, T, F>(v: &'a mut [T], f: F)
- where T: Send + Sync,
- F: Fn(uint, &'a mut [T]) + Sync {
- let (tx, rx) = channel();
+fn parallel<T, F>(v: &mut [T], f: F)
+ where T: Send + Sync,
+ F: Fn(uint, &mut [T]) + Sync {
let size = v.len() / os::num_cpus() + 1;
- for (i, chunk) in v.chunks_mut(size).enumerate() {
- let tx = tx.clone();
-
+ v.chunks_mut(size).enumerate().map(|(i, chunk)| {
// Need to convert `f` and `chunk` to something that can cross the task
// boundary.
let f = Racy(&f as *const _ as *const uint);
let raw = Racy(chunk.repr());
- spawn(move|| {
+ Thread::spawn(move|| {
let f = f.0 as *const F;
unsafe { (*f)(i * size, mem::transmute(raw.0)) }
- drop(tx)
- });
- }
- drop(tx);
- for () in rx.iter() {}
+ })
+ }).collect::<Vec<_>>();
}
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
+use std::comm::{channel, Sender, Receiver};
+use std::str::from_str;
+use std::thread::Thread;
+
fn start(n_tasks: int, token: int) {
let (tx, mut rx) = channel();
tx.send(token);
for i in range(2, n_tasks + 1) {
let (tx, next_rx) = channel();
- spawn(move|| roundtrip(i, tx, rx));
+ Thread::spawn(move|| roundtrip(i, tx, rx)).detach();
rx = next_rx;
}
- spawn(move|| roundtrip(1, tx, rx));
+ Thread::spawn(move|| roundtrip(1, tx, rx)).detach();
}
fn roundtrip(id: int, tx: Sender<int>, rx: Receiver<int>) {
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Useful for checking syscall usage of baseline scheduler usage
-fn main() {
- spawn(move|| {});
-}
use std::collections::VecMap;
use std::os;
+use std::str::from_str;
use std::time::Duration;
use std::uint;
#![allow(non_snake_case)]
-use std::io;
-use std::io::stdio::StdReader;
use std::io::BufferedReader;
+use std::io::stdio::StdReader;
+use std::io;
use std::num::Int;
use std::os;
+use std::str::from_str;
// Computes a single solution to a given 9x9 sudoku
//
// ignore-pretty very bad with line comments
-use std::comm;
+use std::comm::{mod, channel};
use std::os;
+use std::str::from_str;
use std::task;
+use std::thread::Thread;
use std::uint;
fn child_generation(gens_left: uint, tx: comm::Sender<()>) {
// This used to be O(n^2) in the number of generations that ever existed.
// With this code, only as many generations are alive at a time as tasks
// alive at a time,
- spawn(move|| {
+ Thread::spawn(move|| {
if gens_left & 1 == 1 {
task::deschedule(); // shake things up a bit
}
} else {
tx.send(())
}
- });
+ }).detach();
}
fn main() {
use std::os;
use std::task;
use std::uint;
+use std::str::from_str;
fn f(n: uint) {
let mut i = 0u;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
+
fn main() {
let (tx, rx) = channel();
let x = Some(rx);
// Test that binary operators consume their arguments
+use std::ops::{Add, Sub, Mul, Div, Rem, BitAnd, BitXor, BitOr, Shl, Shr};
+
fn add<A: Add<B, ()>, B>(lhs: A, rhs: B) {
lhs + rhs;
drop(lhs); //~ ERROR use of moved value: `lhs`
// Test that move restrictions are enforced on overloaded binary operations
+use std::ops::Add;
+
fn double_move<T: Add<T, ()>>(x: T) {
x
+
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Add;
#[deriving(Clone)]
struct foo(Box<uint>);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Add;
+
#[deriving(Copy)]
struct Point {
x: int,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Index;
+
struct MyVec<T> {
data: Vec<T>,
}
// Test that we still see borrowck errors of various kinds when using
// indexing and autoderef in combination.
+use std::ops::{Index, IndexMut};
+
struct Foo {
x: int,
y: int,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::{Index, IndexMut};
+
struct Foo {
x: int,
y: int,
// Tests (negatively) the ability for the Self type in default methods
// to use capabilities granted by builtin kinds as supertraits.
+use std::comm::{channel, Sender};
+
trait Foo : Sync+'static {
fn foo(self, mut chan: Sender<Self>) { }
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::Receiver;
+
fn test<T: Sync>() {}
fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::Sender;
+
fn test<T: Sync>() {}
fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
+use std::thread::Thread;
+
fn main() {
let (tx, rx) = channel();
- spawn(move|| {
+ let _t = Thread::spawn(move|| -> () {
loop {
let tx = tx;
//~^ ERROR: use of moved value: `tx`
use std::ptr;
use std::raw;
+trait Slice {}
+
fn main() {
unsafe {
let nil: *const u8 = ptr::null();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Deref;
+
struct MyPtr<'a>(&'a mut uint);
impl<'a> Deref<uint> for MyPtr<'a> {
fn deref<'b>(&'b self) -> &'b uint { self.0 }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::num::ToPrimitive;
+
trait Add {
fn to_int(&self) -> int;
fn add_dynamic(&self, other: &Add) -> int;
// Test that move restrictions are enforced on overloaded unary operations
+use std::ops::Not;
+
fn move_then_borrow<T: Not<T> + Clone>(x: T) {
!x;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
// Test that a class with an unsendable field can't be
// sent
// (In this case the mul method should take &f64 and not f64)
// See: #11450
+use std::ops::Mul;
+
struct Vec1 {
x: f64
}
#[phase(plugin, link)]
extern crate "std" as std;
#[prelude_import]
-use std::prelude::*;
+use std::prelude::v1::*;
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
// Basic boolean tests
+use std::cmp::{Equal, Greater, Less};
+use std::ops::{BitAnd, BitOr, BitXor};
+
fn main() {
assert_eq!(false.eq(&true), false);
assert_eq!(false == false, true);
// a Send. Basically this just makes sure rustc is using
// each_bound_trait_and_supertraits in type_contents correctly.
+use std::comm::{channel, Sender};
+
trait Bar : Send { }
trait Foo : Bar { }
// even when using them cross-crate.
extern crate trait_superkinds_in_metadata;
+
+use std::comm::{channel, Sender, Receiver};
use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
#[deriving(PartialEq)]
// builtin-kinds, e.g., if a trait requires Send to implement, then
// at usage site of that trait, we know we have the Send capability.
+use std::comm::{channel, Sender, Receiver};
+
trait Foo : Send { }
impl <T: Send> Foo for T { }
// Tests the ability for the Self type in default methods to use
// capabilities granted by builtin kinds as supertraits.
+use std::comm::{Sender, channel};
+
trait Foo : Send {
fn foo(self, tx: Sender<Self>) {
tx.send(self);
extern crate libc;
+use std::c_str::ToCStr;
+
mod mlibc {
use libc::{c_char, c_long, c_longlong};
extern crate log;
use log::{set_logger, Logger, LogRecord};
+use std::comm::channel;
use std::fmt;
use std::io::{ChanReader, ChanWriter};
+use std::thread::Thread;
struct MyWriter(ChanWriter);
fn main() {
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
set_logger(box MyWriter(w) as Box<Logger+Send>);
debug!("debug");
info!("info");
#![feature(unboxed_closures)]
-use std::comm;
+use std::comm::channel;
fn foo<F:FnOnce()+Send>(blk: F) {
blk();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::cmp::Ordering;
+
// Test default methods in PartialOrd and PartialEq
//
struct Fool(bool);
// except according to those terms.
use std::task;
+use std::comm::{channel, Sender};
pub fn main() {
let (tx, rx) = channel();
// except according to those terms.
use std::{str, string};
+use std::c_str::ToCStr;
const A: [u8; 2] = ['h' as u8, 'i' as u8];
const B: &'static [u8; 2] = &A;
use std::io::{Process, Command, timer};
use std::time::Duration;
use std::str;
+use std::comm::channel;
+use std::thread::Thread;
macro_rules! succeed( ($e:expr) => (
match $e { Ok(..) => {}, Err(e) => panic!("panic: {}", e) }
let (tx, rx1) = channel();
let mut t = timer::Timer::new().unwrap();
let rx2 = t.oneshot(Duration::milliseconds(1000));
- spawn(move|| {
+ Thread::spawn(move|| {
select! {
() = rx2.recv() => unsafe { libc::exit(1) },
() = rx1.recv() => {}
}
- });
+ }).detach();
match p.wait().unwrap() {
ExitStatus(..) => panic!("expected a signal"),
ExitSignal(..) => tx.send(()),
// Test that `&mut T` implements `DerefMut<T>`
+use std::ops::DerefMut;
+
fn inc<T:DerefMut<int>>(mut t: T) {
*t += 1;
}
// Test that `&T` and `&mut T` implement `Deref<T>`
+use std::ops::Deref;
+
fn deref<U:Copy,T:Deref<U>>(t: T) -> U {
*t
}
// where possible, by having a type that panics when compared as the
// second element, so this passes iff the instances shortcircuit.
+use std::cmp::Ordering;
+
pub struct FailCmp;
impl PartialEq for FailCmp {
fn eq(&self, _: &FailCmp) -> bool { panic!("eq") }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
+use std::ops::Add;
use std::num::Zero;
#[deriving(Zero)]
// except according to those terms.
use std::task;
+use std::comm::{channel, Sender};
#[deriving(PartialEq, Show)]
enum Message {
// Test that a custom deref with a fat pointer return type does not ICE
+use std::ops::{Deref, DerefMut};
+
pub struct Arr {
ptr: Box<[uint]>
}
// Test that a custom deref with a fat pointer return type does not ICE
+use std::ops::Deref;
+
pub struct Arr {
ptr: Box<[uint]>
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::{Deref, DerefMut};
+
// Generic unique/owned smaht pointer.
struct Own<T> {
value: *mut T
// ignore-fast doesn't like extern crate
extern crate libc;
+use std::c_str::ToCStr;
mod mlibc {
- extern crate libc;
- use self::libc::{c_char, size_t};
+ use libc::{c_char, size_t};
extern {
#[link_name = "strlen"]
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
-extern crate collections;
-
/**
A somewhat reduced test case to expose some Valgrind issues.
mod map_reduce {
use std::collections::HashMap;
+ use std::comm::{channel, Sender};
use std::str;
use std::task;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Deref;
+
struct Root {
jsref: JSRef
}
// This test may not always fail, but it can be flaky if the race it used to
// expose is still present.
+use std::comm::{channel, Sender, Receiver};
+use std::thread::Thread;
+
fn helper(rx: Receiver<Sender<()>>) {
for tx in rx.iter() {
let _ = tx.send_opt(());
fn main() {
let (tx, rx) = channel();
- spawn(move|| { helper(rx) });
+ let _t = Thread::spawn(move|| { helper(rx) }).detach();
let (snd, rcv) = channel::<int>();
for _ in range(1i, 100000i) {
snd.send(1i);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Index;
+
struct Mat<T> { data: Vec<T>, cols: uint, }
impl<T> Mat<T> {
#![feature(unboxed_closures)]
+use std::thread::Thread;
use std::mem;
fn main() {
// Check that both closures are capturing by value
assert_eq!(1, mem::size_of_val(&closure));
- spawn(move|| {
+ Thread::spawn(move|| {
let ok = closure;
- })
+ }).join().ok().unwrap();
}
#![feature(unboxed_closures)]
+use std::ops::{Deref, DerefMut};
+
struct X(Box<int>);
static mut DESTRUCTOR_RAN: bool = false;
#![feature(default_type_params)]
use std::task;
+use std::comm::Sender;
use std::thunk::Invoke;
type RingBuffer = Vec<f64> ;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Mul;
+
struct Vec2 {
x: f64,
y: f64
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Add;
+
trait Positioned<S> {
fn SetX(&mut self, S);
fn X(&self) -> S;
// except according to those terms.
use std::io::println;
+use std::comm::channel;
+use std::thread::Thread;
pub fn main() {
let (tx, rx) = channel();
tx.send("hello, world");
- spawn(move|| {
+ Thread::spawn(move|| {
println(rx.recv());
- });
+ }).join().ok().unwrap();
}
// except according to those terms.
use std::task;
+use std::comm::channel;
pub fn main() {
let (tx, rx) = channel::<&'static str>();
#![feature(advanced_slice_patterns)]
+use std::ops::Add;
+
fn foo<T: Add<T, T> + Clone>([x, y, z]: [T; 3]) -> (T, T, T) {
(x.clone(), x.clone() + y.clone(), x + y + z)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::thread::Thread;
+use std::comm::{channel, Receiver};
+
fn periodical(n: int) -> Receiver<bool> {
let (chan, port) = channel();
- spawn(move|| {
+ Thread::spawn(move|| {
loop {
for _ in range(1, n) {
match chan.send_opt(false) {
Err(..) => break
}
}
- });
+ }).detach();
return port;
}
fn integers() -> Receiver<int> {
let (chan, port) = channel();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut i = 1;
loop {
match chan.send_opt(i) {
}
i = i + 1;
}
- });
+ }).detach();
return port;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::comm;
+use std::comm::{mod, channel};
use std::io::timer::Timer;
+use std::thread::Thread;
use std::time::Duration;
pub fn main() {
let (tx, rx) = channel();
- spawn(move||{
+ let _t = Thread::spawn(move||{
let mut timer = Timer::new().unwrap();
timer.sleep(Duration::milliseconds(10));
tx.send(());
// except according to those terms.
use std::task;
+use std::comm::{channel, Sender};
fn producer(tx: &Sender<Vec<u8>>) {
tx.send(
use std::cell::Cell;
use std::fmt;
+use std::thread::Thread;
struct Foo(Cell<int>);
}
pub fn main() {
- let (tx, rx) = channel();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut f = Foo(Cell::new(0));
println!("{}", f);
let Foo(ref mut f) = f;
assert!(f.get() == 1);
- tx.send(());
- });
- rx.recv();
+ }).join().ok().unwrap();
}
#![feature(macro_rules)]
+use std::thread::Thread;
+
macro_rules! expr (($e: expr) => { $e });
macro_rules! spawn {
($($code: tt)*) => {
- expr!(spawn(move|| {$($code)*}))
+ expr!(Thread::spawn(move|| {$($code)*}).detach())
}
}
// except according to those terms.
use std::uint;
+use std::str::from_str;
pub fn main() {
// sometimes we have had trouble finding
// necessary. Testing the methods of the impls is done within the source
// file for each numeric type.
+use std::ops::Add;
+use std::num::ToPrimitive;
+
pub fn main() {
// ints
// num
use std::io::process::Command;
use std::os;
+use std::thread::Thread;
// lifted from the test module
// Inlining to avoid llvm turning the recursive functions into tail calls,
let args = os::args();
let args = args.as_slice();
if args.len() > 1 && args[1].as_slice() == "recurse" {
- let (tx, rx) = channel();
- spawn(move|| {
- recurse();
- tx.send(());
- });
- rx.recv();
+ let _t = Thread::spawn(recurse);
} else {
let recurse = Command::new(args[0].as_slice()).arg("recurse").output().unwrap();
assert!(!recurse.status.success());
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::Deref;
+
struct DerefArray<'a, T:'a> {
inner: &'a [T]
}
// except according to those terms.
use std::rc::Rc;
+use std::ops::Deref;
struct DerefWrapper<X, Y> {
x: X,
}
mod priv_test {
+ use std::ops::Deref;
+
pub struct DerefWrapperHideX<X, Y> {
x: X,
pub y: Y
use std::cell::RefCell;
use std::rc::Rc;
-use std::string::String;
+use std::num::ToPrimitive;
#[deriving(PartialEq, Show)]
struct Point {
assert_eq!((i_value, *i.borrow()), (2, 5));
let s = Rc::new("foo".to_string());
- assert!(s.equiv(&("foo")));
assert_eq!(s.as_slice(), "foo");
let mut_s = Rc::new(RefCell::new(String::from_str("foo")));
#![feature(unboxed_closures)]
use std::ops::Fn;
+use std::ops::Add;
struct G;
// Test overloaded indexing combined with autoderef.
+use std::ops::{Index, IndexMut};
+
struct Foo {
x: int,
y: int,
// Test using overloaded indexing when the "map" is stored in a
// field. This caused problems at some point.
+use std::ops::Index;
+
struct Foo {
x: int,
y: int,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::ops::{Index, IndexMut};
+
struct Foo {
x: int,
y: int,
extern crate libc;
use std::io::TempDir;
+use std::c_str::ToCStr;
use std::io::fs::PathExtensions;
use std::io::fs;
use std::io;
use std::io::process::{Command, ProcessOutput};
use std::os;
-use std::str;
+use std::rt::unwind::try;
use std::rt;
+use std::str;
+use std::thread::Thread;
use std::thunk::Thunk;
-use std::rt::unwind::try;
-
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
if argc > 1 {
2 => println!("foo"),
3 => assert!(try(|| {}).is_ok()),
4 => assert!(try(|| panic!()).is_err()),
- 5 => assert!(try(|| spawn(move|| {})).is_err()),
- 6 => assert!(Command::new("test").spawn().is_err()),
+ 5 => assert!(Command::new("test").spawn().is_err()),
_ => panic!()
}
}
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[5u8];
pass(Command::new(me).arg(x).output().unwrap());
- let x: &[u8] = &[6u8];
- pass(Command::new(me).arg(x).output().unwrap());
0
}
#[phase(plugin,link)]
extern crate log;
+use std::comm::{channel, Sender, Receiver};
+use std::thread::Thread;
+
pub struct ChannelLogger {
tx: Sender<String>
}
pub fn main() {
let (logger, rx) = ChannelLogger::new();
- spawn(move|| {
+ let _t = Thread::spawn(move|| {
log::set_logger(logger);
// our regex is "f.o"
// except according to those terms.
use std::task;
+use std::comm::channel;
struct test {
f: int,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::{channel, Sender};
+
// tests that ctrl's type gets inferred properly
struct Command<K, V> {
key: K,
extern crate collections;
use std::collections::HashMap;
-use std::option::Option::Some;
use std::str::SendStr;
+use std::borrow::IntoCow;
pub fn main() {
let mut map: HashMap<SendStr, uint> = HashMap::new();
extern crate collections;
use self::collections::BTreeMap;
-use std::option::Option::Some;
use std::str::SendStr;
-use std::string::ToString;
+use std::borrow::IntoCow;
pub fn main() {
let mut map: BTreeMap<SendStr, uint> = BTreeMap::new();
// Test that a class with only sendable fields can be sent
+use std::comm::channel;
+
struct foo {
i: int,
j: char,
*/
use std::task;
+use std::comm::{channel, Sender};
type ctx = Sender<int>;
// There is some other borrowck bug, so we make the stuff not mut.
+use std::ops::Add;
+
trait Positioned<S> {
fn SetX(&mut self, S);
fn X(&self) -> S;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
use std::task;
+use std::comm::{channel, Sender};
pub fn main() { test05(); }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
use std::task;
+use std::comm::{channel, Sender};
fn start(tx: &Sender<Sender<String>>) {
let (tx2, rx) = channel();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
+use std::comm::{channel, Sender};
use std::task;
fn start(tx: &Sender<Sender<int>>) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
+use std::comm::{channel, Sender};
use std::task;
fn start(tx: &Sender<int>, start: int, number_of_messages: int) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
+use std::comm::{channel, Sender};
use std::task;
pub fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
+use std::comm::{channel, Sender};
use std::task;
fn start(tx: &Sender<int>, i0: int) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
use std::cmp;
// Tests of ports and channels on various types
// no-pretty-expanded FIXME #15189
use std::thread::Thread;
+use std::comm::{channel, Sender};
pub fn main() { println!("===== WITHOUT THREADS ====="); test00(); }
#![allow(dead_assignment)]
+use std::comm::channel;
+
pub fn main() { test00(); }
fn test00() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
+
pub fn main() { test00(); }
fn test00() {
#![allow(dead_assignment)]
+use std::comm::channel;
+
pub fn main() { test00(); }
fn test00() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
#![allow(dead_assignment)]
+use std::comm::{channel, Sender};
use std::task;
pub fn main() { test00(); }
// except according to those terms.
use std::thread::Thread;
+use std::comm::{channel, Sender};
pub fn main() { test00(); }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
+
// rustboot can't transmit nils across channels because they don't have
// any size, but rustc currently can because they do have size. Whether
// or not this is desirable I don't know, but here's a regression test.
// except according to those terms.
use std::task;
+use std::comm::channel;
pub fn main() {
let (tx, rx) = channel::<uint>();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
use std::io::{ChanReader, ChanWriter};
use std::thread;
// quite quickly and it takes a few seconds for the sockets to get
// recycled.
+use std::comm::channel;
use std::io::{TcpListener, Listener, Acceptor, EndOfFile, TcpStream};
use std::sync::{atomic, Arc};
+use std::thread::Thread;
static N: uint = 8;
static M: uint = 20;
let a = a.clone();
let cnt = cnt.clone();
let srv_tx = srv_tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
let mut a = a;
loop {
match a.accept() {
}
}
srv_tx.send(());
- });
+ }).detach();
}
for _ in range(0, N) {
let cli_tx = cli_tx.clone();
- spawn(move|| {
+ Thread::spawn(move|| {
for _ in range(0, M) {
let _s = TcpStream::connect(addr).unwrap();
}
cli_tx.send(());
- });
+ }).detach();
}
drop((cli_tx, srv_tx));
use std::io::test::*;
use std::io;
use std::time::Duration;
+use std::comm::channel;
#[cfg_attr(target_os = "freebsd", ignore)]
fn eventual_timeout() {
use std::io;
use std::os;
use std::task;
+use std::comm::channel;
fn test_tempdir() {
let path = {
// Tests that a heterogeneous list of existential types can be put inside an Arc
// and shared between tasks as long as all types fulfill Send.
-
use std::sync::Arc;
+use std::comm::channel;
use std::task;
trait Pet {
// except according to those terms.
use std::cmp::PartialEq;
+use std::ops::{Add, Sub, Mul};
trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone { }
message.
*/
+use std::comm::channel;
+
pub fn main() {
let (tx, rx) = channel();
tx.send(42i);
#![feature(unboxed_closures)]
+use std::num::ToPrimitive;
+
fn doit<T,F>(val: T, f: &F)
where F : Fn(T)
{
#![feature(unboxed_closures)]
+use std::num::ToPrimitive;
+
fn doit<T>(val: T, f: &Fn(T)) { f.call((val,)) }
pub fn main() {
#![feature(unboxed_closures)]
+use std::num::ToPrimitive;
+
fn doit<T,F>(val: T, f: &F)
where F : Fn(&T)
{
// except according to those terms.
use std::task;
+use std::comm::{channel, Sender};
fn child(tx: &Sender<Box<uint>>, i: uint) {
tx.send(box i);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::comm::channel;
+
pub fn main() {
let (tx, rx) = channel();
tx.send(box 100i);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
+use std::comm::{channel, Sender};
use std::task;
struct complainer {
// except according to those terms.
extern crate libc;
-use std::c_str::CString;
+
+use std::c_str::{CString, ToCStr};
use libc::{c_char, c_int};
// ignore-fast doesn't like extern crate
use std::io::process::Command;
use std::iter::IteratorExt;
+use std::str::from_str;
use libc::funcs::posix88::unistd;
-
// The output from "ps -A -o pid,ppid,args" should look like this:
// PID PPID COMMAND
// 1 0 /sbin/init