diff options
Diffstat (limited to 'src/libstd')
93 files changed, 975 insertions, 801 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 7bd955a905b..db01c091dc0 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -315,8 +315,8 @@ static ASCII_UPPERCASE_MAP: [u8, ..256] = [ #[cfg(test)] mod tests { + use prelude::v1::*; use super::*; - use prelude::*; use char::from_u32; #[test] diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 5dd76047779..1826ad3dc31 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -205,7 +205,7 @@ macro_rules! bitflags { } } - impl BitOr<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitOr<$BitFlags, $BitFlags> for $BitFlags { /// Returns the union of the two sets of flags. #[inline] fn bitor(self, other: $BitFlags) -> $BitFlags { @@ -213,7 +213,7 @@ macro_rules! bitflags { } } - impl BitXor<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitXor<$BitFlags, $BitFlags> for $BitFlags { /// Returns the left flags, but with all the right flags toggled. #[inline] fn bitxor(self, other: $BitFlags) -> $BitFlags { @@ -221,7 +221,7 @@ macro_rules! bitflags { } } - impl BitAnd<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::BitAnd<$BitFlags, $BitFlags> for $BitFlags { /// Returns the intersection between the two sets of flags. #[inline] fn bitand(self, other: $BitFlags) -> $BitFlags { @@ -229,7 +229,7 @@ macro_rules! bitflags { } } - impl Sub<$BitFlags, $BitFlags> for $BitFlags { + impl ::std::ops::Sub<$BitFlags, $BitFlags> for $BitFlags { /// Returns the set difference of the two sets of flags. #[inline] fn sub(self, other: $BitFlags) -> $BitFlags { @@ -239,7 +239,7 @@ macro_rules! bitflags { // NOTE(stage0): Remove impl after a snapshot #[cfg(stage0)] - 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 { @@ -248,7 +248,7 @@ macro_rules! bitflags { } #[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot - 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 { diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index ffe19203769..fa0d8fa9bd5 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -45,6 +45,8 @@ //! ```rust //! extern crate libc; //! +//! use std::c_str::ToCStr; +//! //! extern { //! fn puts(s: *const libc::c_char); //! } @@ -70,6 +72,7 @@ use core::prelude::*; use libc; +use cmp::Ordering; use fmt; use hash; use mem; @@ -155,6 +158,8 @@ impl CString { /// one). /// /// ```rust + /// use std::c_str::ToCStr; + /// /// let foo = "some string"; /// /// // right @@ -170,6 +175,8 @@ impl CString { /// ```rust /// extern crate libc; /// + /// use std::c_str::ToCStr; + /// /// fn main() { /// let c_str = "foo bar".to_c_str(); /// unsafe { @@ -189,6 +196,8 @@ impl CString { /// one). /// /// ```rust + /// use std::c_str::ToCStr; + /// /// let foo = "some string"; /// /// // right @@ -309,6 +318,8 @@ pub trait ToCStr for Sized? { /// ```rust /// extern crate libc; /// + /// use std::c_str::ToCStr; + /// /// fn main() { /// let s = "PATH".with_c_str(|path| unsafe { /// libc::getenv(path) @@ -537,7 +548,7 @@ pub unsafe fn from_c_multistring<F>(buf: *const libc::c_char, #[cfg(test)] mod tests { use super::*; - use prelude::*; + use prelude::v1::*; use ptr; use thread::Thread; use libc; @@ -729,9 +740,10 @@ mod tests { 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) { diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index f4338815f75..d0293aa4a1c 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -172,7 +172,7 @@ impl<T> AsSlice<T> for CVec<T> { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use super::CVec; use libc; diff --git a/src/libstd/collections/hash/bench.rs b/src/libstd/collections/hash/bench.rs index 87aebb24f98..28689767cb0 100644 --- a/src/libstd/collections/hash/bench.rs +++ b/src/libstd/collections/hash/bench.rs @@ -11,7 +11,7 @@ #![cfg(test)] extern crate test; -use prelude::*; +use prelude::v1::*; use self::test::Bencher; use iter::{range_inclusive}; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index d749cd77cef..e7918d605cb 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -87,7 +87,7 @@ impl DefaultResizePolicy { #[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); @@ -1473,8 +1473,9 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Extend<(K, V)> for HashMap<K #[cfg(test)] mod test_map { - use prelude::*; + use prelude::v1::*; + use cmp::Equiv; use super::HashMap; use super::Entry::{Occupied, Vacant}; use hash; diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 6d83d5510b3..e00116344c8 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -844,7 +844,7 @@ impl<'a, T, S, H> Iterator<&'a T> for Union<'a, T, H> #[cfg(test)] mod test_set { - use prelude::*; + use prelude::v1::*; use super::HashSet; diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index c85bea87218..de7f3d00478 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -60,6 +60,7 @@ //! //! ``` //! use std::thread::Thread; +//! use std::comm::channel; //! //! // Create a simple streaming channel //! let (tx, rx) = channel(); @@ -73,6 +74,7 @@ //! //! ``` //! 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 @@ -94,6 +96,8 @@ //! 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>(); @@ -105,6 +109,7 @@ //! //! ``` //! use std::thread::Thread; +//! use std::comm::sync_channel; //! //! let (tx, rx) = sync_channel::<int>(0); //! Thread::spawn(move|| { @@ -120,6 +125,7 @@ //! after 10 seconds no matter what: //! //! ```no_run +//! use std::comm::channel; //! use std::io::timer::Timer; //! use std::time::Duration; //! @@ -143,6 +149,7 @@ //! has been inactive for 5 seconds: //! //! ```no_run +//! use std::comm::channel; //! use std::io::timer::Timer; //! use std::time::Duration; //! @@ -329,21 +336,6 @@ use self::select::StartResult; 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::*; - - $(#[$a])* #[test] fn f() { $b } - } - ) -} - mod blocking; mod oneshot; mod select; @@ -458,6 +450,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> { /// # Example /// /// ``` +/// use std::comm::channel; /// use std::thread::Thread; /// /// // tx is is the sending half (tx for transmission), and rx is the receiving @@ -499,6 +492,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) { /// # Example /// /// ``` +/// use std::comm::sync_channel; /// use std::thread::Thread; /// /// let (tx, rx) = sync_channel(1); @@ -580,6 +574,8 @@ impl<T: Send> Sender<T> { /// # Example /// /// ``` + /// use std::comm::channel; + /// /// let (tx, rx) = channel(); /// /// // This send is always successful @@ -1046,9 +1042,12 @@ unsafe impl<T> kinds::Sync for RacyCell<T> { } // Oh dear #[cfg(test)] mod test { - use super::*; - use prelude::*; + 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") { @@ -1057,121 +1056,144 @@ mod test { } } - 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); } @@ -1179,99 +1201,93 @@ mod test { 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>(); @@ -1280,129 +1296,142 @@ mod test { }).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(); @@ -1412,50 +1441,53 @@ mod test { 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; @@ -1468,13 +1500,14 @@ mod test { 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 { @@ -1492,13 +1525,14 @@ mod test { 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(()); @@ -1515,14 +1549,15 @@ mod test { 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(()); @@ -1537,13 +1572,16 @@ mod test { // 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") { @@ -1552,108 +1590,128 @@ mod sync_tests { } } - 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); } @@ -1662,38 +1720,43 @@ mod sync_tests { _ => {} } 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); @@ -1702,134 +1765,148 @@ mod sync_tests { }).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); @@ -1839,50 +1916,53 @@ mod sync_tests { 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; @@ -1895,13 +1975,14 @@ mod sync_tests { 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 { @@ -1919,13 +2000,14 @@ mod sync_tests { 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(()); @@ -1942,14 +2024,15 @@ mod sync_tests { 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(()); @@ -1964,78 +2047,77 @@ mod sync_tests { // 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(); }); @@ -2047,5 +2129,5 @@ mod sync_tests { for _ in range(0u, 100) { repro() } - } } + } } diff --git a/src/libstd/comm/mpsc_queue.rs b/src/libstd/comm/mpsc_queue.rs index cddef236664..d1b6d0d697c 100644 --- a/src/libstd/comm/mpsc_queue.rs +++ b/src/libstd/comm/mpsc_queue.rs @@ -153,11 +153,12 @@ impl<T: Send> Drop for Queue<T> { #[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() { @@ -181,12 +182,12 @@ mod tests { 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; diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs index 690b5861c22..5c476775bdb 100644 --- a/src/libstd/comm/select.rs +++ b/src/libstd/comm/select.rs @@ -27,6 +27,8 @@ //! # Example //! //! ```rust +//! use std::comm::channel; +//! //! let (tx1, rx1) = channel(); //! let (tx2, rx2) = channel(); //! @@ -335,9 +337,11 @@ impl Iterator<*mut Handle<'static, ()>> for Packets { #[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) @@ -357,7 +361,8 @@ mod test { }) } - test! { fn smoke() { + #[test] + fn smoke() { let (tx1, rx1) = channel::<int>(); let (tx2, rx2) = channel::<int>(); tx1.send(1); @@ -379,9 +384,10 @@ mod test { 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>(); @@ -395,9 +401,10 @@ mod test { _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); @@ -406,14 +413,15 @@ mod test { _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(); @@ -429,14 +437,15 @@ mod test { 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); @@ -454,15 +463,16 @@ mod test { 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); @@ -480,14 +490,15 @@ mod test { } 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)); @@ -501,14 +512,15 @@ mod test { _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)); @@ -522,13 +534,14 @@ mod test { _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); @@ -542,44 +555,49 @@ mod test { 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(()); @@ -587,9 +605,10 @@ mod test { 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(()); @@ -597,18 +616,20 @@ mod test { 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); @@ -617,9 +638,10 @@ mod test { 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(()); @@ -629,12 +651,13 @@ mod test { 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() => {} } @@ -644,16 +667,17 @@ mod test { 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() => {} } @@ -663,15 +687,16 @@ mod test { 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() => {} } @@ -681,32 +706,35 @@ mod test { 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); @@ -717,5 +745,5 @@ mod test { assert_eq!(rx1.recv(), 1); } } - } } + } } diff --git a/src/libstd/comm/spsc_queue.rs b/src/libstd/comm/spsc_queue.rs index becb78063ae..1e2f5222d8b 100644 --- a/src/libstd/comm/spsc_queue.rs +++ b/src/libstd/comm/spsc_queue.rs @@ -240,10 +240,12 @@ impl<T: Send> Drop for Queue<T> { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use sync::Arc; use super::Queue; + use thread::Thread; + use comm::channel; #[test] fn smoke() { @@ -320,7 +322,7 @@ mod test { let (tx, rx) = channel(); let q2 = q.clone(); - spawn(move|| { + let _t = Thread::spawn(move|| { for _ in range(0u, 100000) { loop { match q2.pop() { diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 368abe7cb12..ecfe2d15ae1 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -15,7 +15,9 @@ #![experimental] #![allow(missing_docs)] -use prelude::*; +use prelude::v1::*; + +use c_str::ToCStr; use mem; use os; use str; @@ -146,7 +148,7 @@ impl DynamicLibrary { #[cfg(all(test, not(target_os = "ios")))] mod test { use super::*; - use prelude::*; + use prelude::v1::*; use libc; use mem; @@ -202,8 +204,8 @@ mod test { pub mod dl { use self::Rtld::*; - use prelude::*; - use c_str::CString; + use prelude::v1::*; + use c_str::{CString, ToCStr}; use libc; use ptr; diff --git a/src/libstd/error.rs b/src/libstd/error.rs index cd7d9aacc90..956185c6443 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -78,7 +78,7 @@ //! } //! ``` -use prelude::*; +use prelude::v1::*; use str::Utf8Error; diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs index 7010eae6dba..3d98b6ec40e 100644 --- a/src/libstd/failure.rs +++ b/src/libstd/failure.rs @@ -10,7 +10,7 @@ #![experimental] -use prelude::*; +use prelude::v1::*; use any::{Any, AnyRefExt}; use cell::RefCell; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index c26450310a9..7bf45915273 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -410,7 +410,7 @@ impl<S: Stream> Writer for BufferedStream<S> { mod test { extern crate test; use io; - use prelude::*; + use prelude::v1::*; use super::*; use super::super::{IoResult, EndOfFile}; use super::super::mem::MemReader; diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index 3a18b0dc1b5..be1dc0e9c34 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -23,6 +23,7 @@ use vec::Vec; /// # Example /// /// ``` +/// use std::comm::channel; /// use std::io::ChanReader; /// /// let (tx, rx) = channel(); @@ -114,6 +115,7 @@ impl Reader for ChanReader { /// /// ``` /// # #![allow(unused_must_use)] +/// use std::comm::channel; /// use std::io::ChanWriter; /// /// let (tx, rx) = channel(); @@ -154,7 +156,9 @@ impl Writer for ChanWriter { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; + + use comm::channel; use super::*; use io; use thread::Thread; diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index c1f1a5b7869..dfea9678277 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -175,7 +175,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use io; use io::{MemReader, BytesReader}; @@ -507,7 +507,7 @@ mod test { 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? diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 4e736908c37..20920e60561 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -818,7 +818,7 @@ fn access_string(access: FileAccess) -> &'static str { #[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; diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 01151059530..4341666a27e 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -399,9 +399,10 @@ impl<'a> Buffer for BufReader<'a> { #[cfg(test)] mod test { extern crate "test" as test_crate; + use prelude::v1::*; + use super::*; use io::*; - use prelude::*; use io; use self::test_crate::Bencher; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index b6f8bb25b65..0f8b3de4804 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -233,7 +233,7 @@ use fmt; 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; @@ -1960,7 +1960,7 @@ impl fmt::Show for FilePermission { mod tests { use self::BadReaderBehavior::*; use super::{IoResult, Reader, MemReader, NoProgress, InvalidInput}; - use prelude::*; + use prelude::v1::*; use uint; #[deriving(Clone, PartialEq, Show)] diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 69ba64d856e..18993aaa9d0 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -105,7 +105,7 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option<Hint>) // 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::*; diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index add986387da..ce6bac0f8c4 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -544,7 +544,7 @@ impl<'a> ToSocketAddr for &'a str { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::*; use str::FromStr; diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index 4afc72cde71..f5edf8955d8 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -20,14 +20,14 @@ #![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; @@ -264,13 +264,15 @@ impl sys_common::AsInner<UnixAcceptorImp> for UnixAcceptor { } #[cfg(test)] -#[allow(experimental)] mod tests { - use super::*; + use prelude::v1::*; + + use comm::channel; use io::*; - use io::test::*; - use prelude::*; use io::fs::PathExtensions; + use io::test::*; + use super::*; + use thread::Thread; use time::Duration; pub fn smalltest<F,G>(server: F, client: G) @@ -282,7 +284,7 @@ mod tests { 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), @@ -377,7 +379,7 @@ mod tests { 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]) { @@ -411,7 +413,7 @@ mod tests { 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"); @@ -427,7 +429,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { let mut s2 = s2; rx1.recv(); debug!("writer writing"); @@ -450,7 +452,7 @@ mod tests { 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(); @@ -462,7 +464,7 @@ mod tests { 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(); @@ -481,7 +483,7 @@ mod tests { 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(); @@ -492,7 +494,7 @@ mod tests { 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(()); @@ -539,7 +541,7 @@ mod tests { // 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(); @@ -557,7 +559,7 @@ mod tests { // 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(); @@ -595,11 +597,11 @@ mod tests { 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(); @@ -632,16 +634,16 @@ mod tests { 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(()); @@ -658,12 +660,12 @@ mod tests { 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)); @@ -696,7 +698,7 @@ mod tests { 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; @@ -707,7 +709,7 @@ mod tests { } } let _ = rx.recv_opt(); - }); + }).detach(); let mut s = a.accept().unwrap(); s.set_read_timeout(Some(20)); @@ -725,12 +727,12 @@ mod tests { 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)); @@ -752,17 +754,17 @@ mod tests { 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(()); @@ -784,10 +786,10 @@ mod tests { 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); }); @@ -807,14 +809,14 @@ mod tests { 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); }); @@ -840,7 +842,7 @@ mod tests { let mut a2 = a.clone(); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { let mut a = a; tx.send(a.accept()); }); diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 6adb5387f2e..67aaf7dda8e 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -141,7 +141,7 @@ impl TcpStream { /// 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; @@ -282,10 +282,10 @@ impl sys_common::AsInner<TcpStreamImp> for TcpStream { /// 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) { /// // ... @@ -423,7 +423,7 @@ impl TcpAcceptor { /// 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 { @@ -482,11 +482,14 @@ impl sys_common::AsInner<TcpAcceptorImp> for TcpAcceptor { #[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::*; use io::test::*; - use prelude::*; // FIXME #11530 this fails on android because tests are run as root #[cfg_attr(any(windows, target_os = "android"), ignore)] @@ -512,7 +515,7 @@ mod test { 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(); }); @@ -528,7 +531,7 @@ mod test { 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(); }); @@ -544,7 +547,7 @@ mod test { 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(); }); @@ -560,7 +563,7 @@ mod test { 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(); }); @@ -576,7 +579,7 @@ mod test { 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(); }); @@ -592,7 +595,7 @@ mod test { 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(); }); @@ -608,7 +611,7 @@ mod test { 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 }); @@ -624,7 +627,7 @@ mod test { 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 }); @@ -640,7 +643,7 @@ mod test { 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 }); @@ -664,7 +667,7 @@ mod test { 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 }); @@ -689,7 +692,7 @@ mod test { let mut acceptor = TcpListener::bind(addr).listen(); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { drop(TcpStream::connect(addr)); tx.send(()); }); @@ -714,7 +717,7 @@ mod test { let mut acceptor = TcpListener::bind(addr).listen(); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { drop(TcpStream::connect(addr)); tx.send(()); }); @@ -739,7 +742,7 @@ mod test { 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(); @@ -759,7 +762,7 @@ mod test { 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(); @@ -779,11 +782,11 @@ mod test { 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(); @@ -798,7 +801,7 @@ mod test { 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 @@ -815,11 +818,11 @@ mod test { 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(); @@ -834,7 +837,7 @@ mod test { 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 @@ -851,11 +854,11 @@ mod test { 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(); @@ -870,7 +873,7 @@ mod test { 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 @@ -887,11 +890,11 @@ mod test { 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(); @@ -906,7 +909,7 @@ mod test { 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 @@ -929,7 +932,7 @@ mod test { 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(); }); @@ -964,7 +967,7 @@ mod test { 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(); @@ -1001,7 +1004,7 @@ mod test { 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 @@ -1026,7 +1029,7 @@ mod test { 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)); @@ -1039,7 +1042,7 @@ mod test { 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(); @@ -1058,7 +1061,7 @@ mod test { 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(); @@ -1070,7 +1073,7 @@ mod test { 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(); @@ -1089,7 +1092,7 @@ mod test { 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(); @@ -1100,7 +1103,7 @@ mod test { 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(()); @@ -1114,7 +1117,7 @@ mod test { 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!())); @@ -1148,7 +1151,7 @@ mod test { // 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(); @@ -1165,7 +1168,7 @@ mod test { // 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(); @@ -1176,11 +1179,11 @@ mod test { 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(); @@ -1213,16 +1216,16 @@ mod test { 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(()); @@ -1239,12 +1242,12 @@ mod test { 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)); @@ -1272,7 +1275,7 @@ mod test { 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; @@ -1283,7 +1286,7 @@ mod test { } } let _ = rx.recv_opt(); - }); + }).detach(); let mut s = a.accept().unwrap(); s.set_read_timeout(Some(20)); @@ -1301,12 +1304,12 @@ mod test { 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)); @@ -1329,17 +1332,17 @@ mod test { 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(()); @@ -1362,7 +1365,7 @@ mod test { 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(); @@ -1373,7 +1376,7 @@ mod test { 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(()); @@ -1399,10 +1402,10 @@ mod test { 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); }); @@ -1420,13 +1423,13 @@ mod test { 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); }); @@ -1452,7 +1455,7 @@ mod test { let mut a2 = a.clone(); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { let mut a = a; tx.send(a.accept()); }); diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index a36703172c3..84269eb1ed9 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -248,11 +248,14 @@ impl Writer for UdpStream { #[cfg(test)] #[allow(experimental)] mod test { - use super::*; - use io::net::ip::*; + use prelude::v1::*; + + use comm::channel; use io::*; + use io::net::ip::*; use io::test::*; - use prelude::*; + 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)] @@ -272,7 +275,7 @@ mod test { 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(); @@ -307,7 +310,7 @@ mod test { 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(); @@ -343,7 +346,7 @@ mod test { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { let send_as = |ip, val: &[u8]| { match UdpSocket::bind(ip) { Ok(client) => { @@ -387,7 +390,7 @@ mod test { 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; @@ -449,7 +452,7 @@ mod test { 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))); @@ -461,7 +464,7 @@ mod test { 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(); @@ -482,7 +485,7 @@ mod test { 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(); @@ -493,7 +496,7 @@ mod test { 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(); @@ -517,7 +520,7 @@ mod test { 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]; @@ -533,7 +536,7 @@ mod test { 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(()); } @@ -561,7 +564,7 @@ mod test { 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(())); diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index 73a893c4f2d..40ae4922823 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -15,7 +15,7 @@ #![allow(missing_docs)] -use prelude::*; +use prelude::v1::*; use io::IoResult; use libc; @@ -112,7 +112,10 @@ impl Writer for PipeStream { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; + + use comm::channel; + use thread::Thread; #[test] fn partial_read() { @@ -123,7 +126,7 @@ mod test { 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 diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 93aa627ffba..d1e9e2c4ea1 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -16,25 +16,25 @@ 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. @@ -741,16 +741,17 @@ impl Drop for Process { #[cfg(test)] mod tests { - #![allow(unused_imports)] + use prelude::v1::*; - use super::*; - use io::timer::*; + use comm::channel; use io::*; - use prelude::*; use io::fs::PathExtensions; - use time::Duration; - use str; + use io::timer::*; 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. @@ -1154,14 +1155,14 @@ mod tests { 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); diff --git a/src/libstd/io/result.rs b/src/libstd/io/result.rs index 32965d23971..c1474650f1e 100644 --- a/src/libstd/io/result.rs +++ b/src/libstd/io/result.rs @@ -78,7 +78,7 @@ impl<T, A: Acceptor<T>> Acceptor<T> for IoResult<A> { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::super::mem::*; use io; diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 6bd721599f3..c378b95ff33 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -540,8 +540,11 @@ impl Writer for StdWriter { #[cfg(test)] mod tests { + use prelude::v1::*; + use super::*; - use prelude::*; + use comm::channel; + use thread::Thread; #[test] fn smoke() { @@ -557,7 +560,7 @@ mod tests { 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!"); }); @@ -570,7 +573,7 @@ mod tests { 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"); }); diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index af56735021e..9c6033f37c9 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -12,9 +12,10 @@ #![macro_escape] +use prelude::v1::*; + use libc; use os; -use prelude::*; use std::io::net::ip::*; use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed}; diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index 953effe4345..2067a97fdac 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -225,9 +225,10 @@ fn in_ms_u64(d: Duration) -> u64 { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::Timer; + use thread::Thread; use time::Duration; #[test] @@ -357,9 +358,9 @@ mod 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 @@ -371,9 +372,9 @@ mod 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(); timer.oneshot(Duration::milliseconds(1)); } @@ -384,9 +385,9 @@ mod 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(); timer.sleep(Duration::milliseconds(1)); } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 18fabcbd1a2..e4888f3dd97 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -10,7 +10,7 @@ //! Utility implementations of Reader and Writer -use prelude::*; +use prelude::v1::*; use cmp; use io; use slice::bytes::MutableByteVector; @@ -280,7 +280,7 @@ mod test { use io; use boxed::Box; use super::*; - use prelude::*; + use prelude::v1::*; #[test] fn test_limit_reader_unlimited() { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 8274baeacfa..56d906c8b69 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -264,6 +264,7 @@ mod std { 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; diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index edb6218c5cc..3606f5df5ca 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -474,6 +474,7 @@ macro_rules! vec { /// /// ``` /// use std::thread::Thread; +/// use std::comm::channel; /// /// let (tx1, rx1) = channel(); /// let (tx2, rx2) = channel(); diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 1f76382ce8a..6de49c38b73 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -15,7 +15,7 @@ #![allow(unsigned_negation)] #![doc(primitive = "f32")] -use prelude::*; +use prelude::v1::*; use intrinsics; use libc::c_int; diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 221ecf62c05..50855d21b4a 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -14,7 +14,7 @@ #![allow(missing_docs)] #![doc(primitive = "f64")] -use prelude::*; +use prelude::v1::*; use intrinsics; use libc::c_int; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 7c8763979bb..01aa21c692b 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -147,7 +147,7 @@ pub fn test_num<T>(ten: T, two: T) where #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use super::*; use i8; use i16; @@ -800,7 +800,7 @@ mod bench { extern crate test; use self::test::Bencher; use num::Int; - use prelude::*; + use prelude::v1::*; #[bench] fn bench_pow_function(b: &mut Bencher) { diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index c42b7eebfdd..61fd754018e 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -49,8 +49,9 @@ pub fn to_str_bytes<U, F>(n: $T, radix: uint, f: F) -> U where #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use num::FromStrRadix; + use str::from_str; #[test] pub fn test_from_str() { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index ceb9a4102f6..61ac89239f9 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1424,7 +1424,7 @@ mod arch_consts { #[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}; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 30f3f56bc1c..024dc56073d 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -931,7 +931,9 @@ fn contains_nul<T: BytesContainer>(v: &T) -> bool { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; + use c_str::ToCStr; + use path::{WindowsPath, PosixPath}; #[test] fn test_cstring() { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index d941665f048..da4576ca36d 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -447,11 +447,9 @@ static dot_dot_static: &'static [u8] = b".."; #[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 prelude::v1::*; use str; + use super::*; macro_rules! t { (s: $path:expr, $exp:expr) => ( @@ -1239,7 +1237,7 @@ mod bench { extern crate test; use self::test::Bencher; use super::*; - use prelude::*; + use prelude::v1::*; #[bench] fn join_home_dir(b: &mut Bencher) { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index ea381bc0577..e6fea07b3aa 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1119,10 +1119,8 @@ fn prefix_len(p: Option<PathPrefix>) -> uint { #[cfg(test)] mod tests { + use prelude::v1::*; 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; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs deleted file mode 100644 index d1540f98a23..00000000000 --- a/src/libstd/prelude.rs +++ /dev/null @@ -1,95 +0,0 @@ -// 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}; -#[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::{RawPtr, RawMutPtr}; -#[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, StrVector}; -#[doc(no_inline)] pub use str::StrExt; -#[doc(no_inline)] pub use slice::AsSlice; -#[doc(no_inline)] pub use slice::{VectorVector, 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; diff --git a/src/libstd/prelude/mod.rs b/src/libstd/prelude/mod.rs new file mode 100644 index 00000000000..da945b4c9fa --- /dev/null +++ b/src/libstd/prelude/mod.rs @@ -0,0 +1,42 @@ +// 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; diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs new file mode 100644 index 00000000000..8c4189c37e7 --- /dev/null +++ b/src/libstd/prelude/v1.rs @@ -0,0 +1,50 @@ +// 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 option::Option::{mod, Some, None}; +#[stable] #[doc(no_inline)] pub use ptr::{RawPtr, RawMutPtr}; +#[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::{VectorVector, PartialEqSliceExt}; +#[stable] #[doc(no_inline)] pub use str::{Str, StrVector, 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; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index c590c0f575e..4371fe7e59a 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -419,7 +419,7 @@ pub fn sample<T, I: Iterator<T>, R: Rng>(rng: &mut R, #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::{Rng, task_rng, random, SeedableRng, StdRng, sample}; use iter::order; @@ -615,7 +615,7 @@ static RAND_BENCH_N: u64 = 100; #[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}; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 68c99b12758..95238c0dad9 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -335,10 +335,11 @@ mod imp { #[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] diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index 7298b2ef0ac..642ab3d1e86 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -74,7 +74,7 @@ impl<R: Reader> Rng for ReaderRng<R> { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::ReaderRng; use io::MemReader; diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index b1f268597c7..1fedf9652a0 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -44,7 +44,7 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() } target_os = "freebsd", target_os = "dragonfly"))] mod imp { - use prelude::*; + use prelude::v1::*; use mem; use slice; @@ -107,7 +107,7 @@ mod imp { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use finally::Finally; use super::*; diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 775e9bb526f..d4101bb2152 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -12,7 +12,7 @@ #![allow(non_camel_case_types)] -use prelude::*; +use prelude::v1::*; use os; use sync::atomic; @@ -39,7 +39,7 @@ pub fn log_enabled() -> bool { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use sys_common; macro_rules! t { ($a:expr, $b:expr) => ({ let mut m = Vec::new(); diff --git a/src/libstd/rt/exclusive.rs b/src/libstd/rt/exclusive.rs index 88bdb29caec..eb6b3655444 100644 --- a/src/libstd/rt/exclusive.rs +++ b/src/libstd/rt/exclusive.rs @@ -83,7 +83,7 @@ impl<'a, T: Send> DerefMut<T> for ExclusiveGuard<'a, T> { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use sync::Arc; use super::Exclusive; use task; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index d64336569c6..eb446edbbd8 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -23,14 +23,10 @@ #![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}; @@ -65,9 +61,14 @@ const OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20); #[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; diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 98940a2b381..a8d5216e202 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -496,7 +496,7 @@ impl Death { #[cfg(test)] mod test { use super::*; - use prelude::*; + use prelude::v1::*; use task; use rt::unwind; diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 261a8335173..8c35eb58284 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -57,7 +57,7 @@ //! //! Currently Rust uses unwind runtime provided by libgcc. -use prelude::*; +use prelude::v1::*; use any::Any; use cell::Cell; diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 26dadfd9fb1..d6c0e4a5aea 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -10,13 +10,12 @@ // // 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; diff --git a/src/libstd/sync/atomic.rs b/src/libstd/sync/atomic.rs index 26778ef70b3..5d45836af80 100644 --- a/src/libstd/sync/atomic.rs +++ b/src/libstd/sync/atomic.rs @@ -180,7 +180,7 @@ impl<T: Send> Drop for AtomicOption<T> { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::*; #[test] diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index 6cdb199819a..15a682ad3b8 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -89,10 +89,11 @@ impl Barrier { #[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() { @@ -102,10 +103,10 @@ mod tests { 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, diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index f1940bfd829..984b895b31d 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -8,7 +8,7 @@ // 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::{mutex, StaticMutexGuard}; @@ -262,11 +262,13 @@ impl StaticCondvar { #[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() { @@ -289,7 +291,7 @@ mod tests { static M: StaticMutex = MUTEX_INIT; let g = M.lock(); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = M.lock(); C.notify_one(); }); @@ -307,7 +309,7 @@ mod tests { 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(); *cnt += 1; @@ -318,7 +320,7 @@ mod tests { cond.wait(&cnt); } tx.send(()); - }); + }).detach(); } drop(tx); @@ -341,7 +343,7 @@ mod tests { let g = M.lock(); assert!(!C.wait_timeout(&g, Duration::nanoseconds(1000))); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = M.lock(); C.notify_one(); }); @@ -358,7 +360,7 @@ mod tests { static C: StaticCondvar = CONDVAR_INIT; let g = M1.lock(); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = M1.lock(); C.notify_one(); }); diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index 51899a87a32..a0e7236b8d2 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -150,9 +150,10 @@ impl<A:Send> Future<A> { #[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() { @@ -210,7 +211,7 @@ mod test { 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()); }); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 4d2fbfc4055..87a02bd4ef5 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -8,10 +8,11 @@ // 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, AsMutexGuard}; use sys_common::mutex as sys; @@ -36,6 +37,8 @@ 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 @@ -279,10 +282,11 @@ impl Drop for StaticMutexGuard { #[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)>); @@ -325,9 +329,9 @@ mod test { 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); @@ -351,7 +355,7 @@ mod test { 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; @@ -376,7 +380,7 @@ mod test { 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(); @@ -413,9 +417,9 @@ mod test { 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(); - let lock2 = lock.deref().lock(); + let lock2 = lock.lock(); assert_eq!(*lock2, 1); tx.send(()); }); diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 4d9fbb59908..fe25eca03d7 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -122,10 +122,11 @@ impl Once { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use thread::Thread; use super::{ONCE_INIT, Once}; + use comm::channel; #[test] fn smoke_once() { @@ -145,7 +146,7 @@ mod test { 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(|| { @@ -155,7 +156,7 @@ mod test { assert!(run); } tx.send(()); - }); + }).detach(); } unsafe { diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 76d05d9bfd4..b316cd908b6 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; -use kinds::marker; use cell::UnsafeCell; -use sys_common::rwlock as sys; +use kinds::marker; +use ops::{Deref, DerefMut}; use sync::poison; +use sys_common::rwlock as sys; /// A reader-writer lock /// @@ -359,9 +360,10 @@ impl Drop for StaticRWLockWriteGuard { #[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}; @@ -393,7 +395,7 @@ mod tests { let (tx, rx) = channel::<()>(); for _ in range(0, N) { let tx = tx.clone(); - spawn(move|| { + Thread::spawn(move|| { let mut rng = rand::task_rng(); for _ in range(0, M) { if rng.gen_weighted_bool(N) { @@ -403,7 +405,7 @@ mod tests { } } drop(tx); - }); + }).detach(); } drop(tx); let _ = rx.recv_opt(); diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs index 574b0f22bee..382caa2cf4a 100644 --- a/src/libstd/sync/semaphore.rs +++ b/src/libstd/sync/semaphore.rs @@ -104,10 +104,12 @@ impl<'a> Drop for SemaphoreGuard<'a> { #[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() { @@ -127,7 +129,7 @@ mod tests { 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(); @@ -139,7 +141,7 @@ mod tests { 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(()); }); @@ -150,7 +152,7 @@ mod tests { 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(); }); @@ -166,7 +168,7 @@ mod tests { 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(()); @@ -183,11 +185,11 @@ mod tests { 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 diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 366e4b7d35b..ce7e883e803 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -53,8 +53,9 @@ impl<'a> Drop for Sentinel<'a> { /// # 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); /// @@ -131,8 +132,9 @@ fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::*; + use comm::channel; const TEST_TASKS: uint = 4u; diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs index 1d646eb06b1..c1aace764fc 100644 --- a/src/libstd/sys/common/backtrace.rs +++ b/src/libstd/sys/common/backtrace.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; use io::IoResult; diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs index a629f035b07..5d94e8efeb8 100644 --- a/src/libstd/sys/common/helper_thread.rs +++ b/src/libstd/sys/common/helper_thread.rs @@ -20,12 +20,13 @@ //! 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; diff --git a/src/libstd/sys/common/mod.rs b/src/libstd/sys/common/mod.rs index dc0ad08cdbe..97015f74a4a 100644 --- a/src/libstd/sys/common/mod.rs +++ b/src/libstd/sys/common/mod.rs @@ -12,7 +12,7 @@ #![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; diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 382f6875b28..9ab5077ae79 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -8,23 +8,23 @@ // 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 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; diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index fe7a7d8d037..405dd4eacf3 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -56,7 +56,7 @@ #![allow(non_camel_case_types)] -use prelude::*; +use prelude::v1::*; use sync::atomic::{mod, AtomicUint}; use sync::{Mutex, Once, ONCE_INIT}; @@ -246,7 +246,7 @@ impl Drop for Key { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use super::{Key, StaticKey, INIT_INNER}; fn assert_sync<T: Sync>() {} diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 98d860f9646..d537579d453 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -10,16 +10,15 @@ //! 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}; @@ -360,7 +359,7 @@ mod tests { 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] diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index f3babca3287..15dad810756 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -19,7 +19,7 @@ extern crate libc; use num; use num::{Int, SignedInt}; -use prelude::*; +use prelude::v1::*; use io::{mod, IoResult, IoError}; use sys_common::mkerr_libc; diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index cafe52f8403..a221a6bc15b 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -10,17 +10,18 @@ //! 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; diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index f1b078b4e80..6954866257e 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -8,13 +8,13 @@ // 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}; diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 835f4279d9b..9824c9c7364 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -7,22 +7,23 @@ // <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}; diff --git a/src/libstd/sys/unix/tcp.rs b/src/libstd/sys/unix/tcp.rs index e2a78947e16..13ccf685fd7 100644 --- a/src/libstd/sys/unix/tcp.rs +++ b/src/libstd/sys/unix/tcp.rs @@ -8,12 +8,13 @@ // 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; diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs index b300e93eeb6..e507377a8fc 100644 --- a/src/libstd/sys/unix/thread_local.rs +++ b/src/libstd/sys/unix/thread_local.rs @@ -8,7 +8,7 @@ // 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; diff --git a/src/libstd/sys/unix/timer.rs b/src/libstd/sys/unix/timer.rs index fe393b81e3d..903c4954f6f 100644 --- a/src/libstd/sys/unix/timer.rs +++ b/src/libstd/sys/unix/timer.rs @@ -46,19 +46,19 @@ //! //! 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> } diff --git a/src/libstd/sys/unix/tty.rs b/src/libstd/sys/unix/tty.rs index 28c17fd4966..4ef687d41d8 100644 --- a/src/libstd/sys/unix/tty.rs +++ b/src/libstd/sys/unix/tty.rs @@ -8,8 +8,9 @@ // 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; diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index d1cb91bcdb3..d1177776dd8 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -15,7 +15,7 @@ #![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; @@ -133,7 +133,7 @@ pub mod compat { use intrinsics::{atomic_store_relaxed, transmute}; use iter::IteratorExt; use libc::types::os::arch::extra::{LPCWSTR, HMODULE, LPCSTR, LPVOID}; - use prelude::*; + use prelude::v1::*; extern "system" { fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE; diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 15eddd569be..632261f0ad9 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -21,7 +21,7 @@ use ptr; use str; use io; -use prelude::*; +use prelude::v1::*; use sys; use sys::os; use sys_common::{keep_going, eof, mkerr_libc}; diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 6924687d8c4..94f5822ccea 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -18,9 +18,10 @@ extern crate libc; +use prelude::v1::*; + use num; use mem; -use prelude::*; use io::{mod, IoResult, IoError}; use sync::{Once, ONCE_INIT}; diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 3ac7c09154e..c7b4a4cec09 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -8,7 +8,7 @@ // 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}; diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index e007b46b261..159512525d8 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -13,7 +13,7 @@ // FIXME: move various extern bindings from here into liblibc or // something similar -use prelude::*; +use prelude::v1::*; use fmt; use io::{IoResult, IoError}; diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index fc3640f2604..f173d5fc6d4 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -84,14 +84,14 @@ //! 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}; diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 0c2c76077dd..f99995eb028 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -8,6 +8,8 @@ // 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; @@ -15,7 +17,6 @@ use io; use mem; use os; use ptr; -use prelude::*; use io::process::{ProcessExit, ExitStatus, ExitSignal}; use collections; use path::BytesContainer; @@ -469,7 +470,7 @@ mod tests { #[test] fn test_make_command_line() { - use prelude::*; + use prelude::v1::*; use str; use c_str::CString; use super::make_command_line; diff --git a/src/libstd/sys/windows/tcp.rs b/src/libstd/sys/windows/tcp.rs index 513c1d38e36..5a929f6b2b5 100644 --- a/src/libstd/sys/windows/tcp.rs +++ b/src/libstd/sys/windows/tcp.rs @@ -13,7 +13,7 @@ use io::IoResult; 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; diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 60b0d584db3..b96e26c7a86 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -8,7 +8,7 @@ // 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}; diff --git a/src/libstd/sys/windows/timer.rs b/src/libstd/sys/windows/timer.rs index 874838950cd..3df0debff51 100644 --- a/src/libstd/sys/windows/timer.rs +++ b/src/libstd/sys/windows/timer.rs @@ -29,7 +29,7 @@ use comm; use sys::c; use sys::fs::FileDesc; use sys_common::helper_thread::Helper; -use prelude::*; +use prelude::v1::*; use io::IoResult; helper_init! { static HELPER: Helper<Req> } diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index f793de5bb57..dfa3440067a 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -25,6 +25,8 @@ //! wrapper that performs encoding/decoding, this implementation should switch //! to working in raw UTF-16, with such a wrapper around it. +use prelude::v1::*; + use super::c::{ReadConsoleW, WriteConsoleW, GetConsoleMode, SetConsoleMode}; use super::c::{ERROR_ILLEGAL_CHARACTER}; use super::c::{ENABLE_ECHO_INPUT, ENABLE_EXTENDED_FLAGS}; @@ -34,7 +36,6 @@ use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID}; use libc::{get_osfhandle, CloseHandle}; use libc::types::os::arch::extra::LPCVOID; use io::{mod, IoError, IoResult, MemReader}; -use prelude::*; use ptr; use str::from_utf8; diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 56731bd7ec3..fdf2648faa1 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -439,13 +439,15 @@ impl<T: Send> Drop for JoinGuard<T> { #[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. !!! diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 242dceb4256..674cb5a9805 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -37,7 +37,7 @@ #![macro_escape] #![experimental] -use prelude::*; +use prelude::v1::*; use cell::UnsafeCell; @@ -258,7 +258,7 @@ impl<T: 'static> Key<T> { #[cfg(any(target_os = "macos", target_os = "linux"))] mod imp { - use prelude::*; + use prelude::v1::*; use cell::UnsafeCell; use intrinsics; @@ -396,7 +396,7 @@ mod imp { #[cfg(not(any(target_os = "macos", target_os = "linux")))] mod imp { - use prelude::*; + use prelude::v1::*; use cell::UnsafeCell; use mem; @@ -469,8 +469,9 @@ mod imp { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; + use comm::{channel, Sender}; use cell::UnsafeCell; use thread::Thread; @@ -492,7 +493,7 @@ mod tests { *f.get() = 2; }); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { FOO.with(|f| unsafe { assert_eq!(*f.get(), 1); }); @@ -512,7 +513,7 @@ mod tests { }); 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())); @@ -562,7 +563,7 @@ mod tests { Thread::spawn(move|| { drop(S1); - }).join(); + }).join().ok().unwrap(); } #[test] @@ -580,7 +581,7 @@ mod tests { Thread::spawn(move|| unsafe { K1.with(|s| *s.get() = Some(S1)); - }).join(); + }).join().ok().unwrap(); } #[test] @@ -605,7 +606,7 @@ mod tests { } 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()))); }); @@ -615,7 +616,7 @@ mod tests { #[cfg(test)] mod dynamic_tests { - use prelude::*; + use prelude::v1::*; use cell::RefCell; use collections::HashMap; diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index 756c86c2115..a06048aa706 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -40,7 +40,7 @@ #![macro_escape] -use prelude::*; +use prelude::v1::*; // macro hygiene sure would be nice, wouldn't it? #[doc(hidden)] pub use self::imp::KeyInner; @@ -238,7 +238,7 @@ mod imp { #[cfg(test)] mod tests { use cell::Cell; - use prelude::*; + use prelude::v1::*; #[test] fn smoke() { diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 5cd60d6e153..fc90bffa03c 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -35,14 +35,14 @@ //! //! # 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); //! # } //! ``` //! |
