From 257212afa32adffae71925076b2318000b885235 Mon Sep 17 00:00:00 2001 From: Cristian Cobzarenco Date: Sat, 27 Jun 2015 19:47:34 +0100 Subject: [PATCH] Remove warnings from tests. --- src/libcoretest/iter.rs | 15 ++++++++++++++- src/libstd/fs.rs | 1 - src/libstd/io/buffered.rs | 2 ++ src/libstd/io/error.rs | 2 +- src/libstd/net/addr.rs | 2 -- src/libstd/net/ip.rs | 1 - src/libstd/net/tcp.rs | 4 ++-- src/libstd/net/udp.rs | 4 ++-- src/libstd/num/f32.rs | 12 ++++++------ src/libstd/num/f64.rs | 12 ++++++------ src/libstd/num/mod.rs | 5 ----- src/libstd/os/raw.rs | 1 + src/libstd/rand/os.rs | 2 -- src/libstd/rand/reader.rs | 2 -- src/libstd/rt/mod.rs | 6 +++--- src/libstd/sys/common/remutex.rs | 32 +++++++++++++++----------------- src/libstd/sys/common/stack.rs | 1 + src/libstd/sys/unix/process.rs | 3 +-- src/libstd/thread/mod.rs | 18 ++++++++++-------- src/libstd/thread/scoped_tls.rs | 1 - 20 files changed, 64 insertions(+), 62 deletions(-) diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index dca899a8e9f7a..2652109c6cadc 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -452,6 +452,7 @@ fn test_inspect() { } #[test] +#[allow(deprecated)] fn test_unfoldr() { fn count(st: &mut usize) -> Option { if *st < 10 { @@ -782,6 +783,7 @@ fn test_rposition_panic() { #[cfg(test)] +#[allow(deprecated)] fn check_randacc_iter(a: T, len: usize) where A: PartialEq, T: Clone + RandomAccessIterator + Iterator, @@ -821,6 +823,7 @@ fn test_double_ended_flat_map() { } #[test] +#[allow(deprecated)] fn test_random_access_chain() { let xs = [1, 2, 3, 4, 5]; let ys = [7, 9, 11]; @@ -884,6 +887,7 @@ fn test_random_access_skip() { } #[test] +#[allow(deprecated)] fn test_random_access_inspect() { let xs = [1, 2, 3, 4, 5]; @@ -897,6 +901,7 @@ fn test_random_access_inspect() { } #[test] +#[allow(deprecated)] fn test_random_access_map() { let xs = [1, 2, 3, 4, 5]; @@ -985,12 +990,19 @@ fn test_range_step() { } #[test] -fn test_reverse() { +#[allow(deprecated)] +fn test_reverse_in_place() { let mut ys = [1, 2, 3, 4, 5]; ys.iter_mut().reverse_in_place(); assert!(ys == [5, 4, 3, 2, 1]); } +#[test] +fn test_reverse() { + let ys = [1, 2, 3, 4, 5].iter().cloned().rev().collect::>(); + assert_eq!(&ys, &[5, 4, 3, 2, 1]); +} + #[test] fn test_peekable_is_empty() { let a = [1]; @@ -1031,6 +1043,7 @@ fn test_min_max_result() { } #[test] +#[allow(deprecated)] fn test_iterate() { let mut it = iterate(1, |x| x * 2); assert_eq!(it.next(), Some(1)); diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 2b0f17fb2bb9c..e41aeaac5ea10 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1311,7 +1311,6 @@ mod tests { use io::{ErrorKind, SeekFrom}; use path::PathBuf; use path::Path as Path2; - use os; use rand::{self, StdRng, Rng}; use str; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 1d0152e275117..10b6ebbe79307 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -741,6 +741,7 @@ mod tests { // This is just here to make sure that we don't infinite loop in the // newtype struct autoderef weirdness #[test] + #[allow(deprecated)] fn test_buffered_stream() { struct S; @@ -892,6 +893,7 @@ mod tests { } #[bench] + #[allow(deprecated)] fn bench_buffered_stream(b: &mut test::Bencher) { let mut buf = Cursor::new(Vec::new()); b.iter(|| { diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index a66789bf2873d..12b1e34b85430 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -309,7 +309,7 @@ mod test { struct TestError; impl fmt::Display for TestError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result { Ok(()) } } diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index b0bf9d0f80626..319eb3bda400c 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -458,9 +458,7 @@ impl<'a, T: ToSocketAddrs + ?Sized> ToSocketAddrs for &'a T { #[cfg(test)] mod tests { use prelude::v1::*; - use io; use net::*; - use net::Ipv6MulticastScope::*; use net::test::{tsa, sa6, sa4}; #[test] diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index bc13d966a10b7..7864515a1d0ea 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -514,7 +514,6 @@ impl FromInner for Ipv6Addr { #[cfg(test)] mod tests { use prelude::v1::*; - use io; use net::*; use net::Ipv6MulticastScope::*; use net::test::{tsa, sa6, sa4}; diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 222059e4c0e6a..9facebdb4805e 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -908,7 +908,7 @@ mod tests { #[test] fn timeouts() { let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); + let _listener = t!(TcpListener::bind(&addr)); let stream = t!(TcpStream::connect(&("localhost", addr.port()))); let dur = Duration::new(15410, 0); @@ -933,7 +933,7 @@ mod tests { #[test] fn test_read_timeout() { let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); + let _listener = t!(TcpListener::bind(&addr)); let mut stream = t!(TcpStream::connect(&("localhost", addr.port()))); t!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index c3cf9895205e4..4b659b9485d7c 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -391,7 +391,7 @@ mod tests { fn test_read_timeout() { let addr = next_test_ip4(); - let mut stream = t!(UdpSocket::bind(&addr)); + let stream = t!(UdpSocket::bind(&addr)); t!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); let mut buf = [0; 10]; @@ -407,7 +407,7 @@ mod tests { fn test_read_with_timeout() { let addr = next_test_ip4(); - let mut stream = t!(UdpSocket::bind(&addr)); + let stream = t!(UdpSocket::bind(&addr)); t!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); t!(stream.send_to(b"hello world", &addr)); diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 0c40f6c1fc8a8..62a64ab9defc7 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -15,12 +15,11 @@ #![allow(unsigned_negation)] #![doc(primitive = "f32")] -use prelude::v1::*; - -use core::num; -use intrinsics; -use libc::c_int; -use num::{FpCategory, ParseFloatError}; +#[cfg(not(test))] use prelude::v1::*; +#[cfg(not(test))] use core::num; +#[cfg(not(test))] use intrinsics; +#[cfg(not(test))] use libc::c_int; +#[cfg(not(test))] use num::{FpCategory, ParseFloatError}; pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON}; pub use core::f32::{MIN_EXP, MAX_EXP, MIN_10_EXP}; @@ -1690,6 +1689,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_real_consts() { use super::consts; diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 41c0fcb9797a6..0b80a69ca3fd1 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -14,12 +14,11 @@ #![allow(missing_docs)] #![doc(primitive = "f64")] -use prelude::v1::*; - -use core::num; -use intrinsics; -use libc::c_int; -use num::{FpCategory, ParseFloatError}; +#[cfg(not(test))] use prelude::v1::*; +#[cfg(not(test))] use core::num; +#[cfg(not(test))] use intrinsics; +#[cfg(not(test))] use libc::c_int; +#[cfg(not(test))] use num::{FpCategory, ParseFloatError}; pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON}; pub use core::f64::{MIN_EXP, MAX_EXP, MIN_10_EXP}; @@ -1646,6 +1645,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_real_consts() { use super::consts; let pi: f64 = consts::PI; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 9a52a0214e9cc..e829ad45ef24a 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -45,11 +45,6 @@ pub fn test_num(ten: T, two: T) where mod tests { use core::prelude::*; use super::*; - use i8; - use i16; - use i32; - use i64; - use isize; use u8; use u16; use u32; diff --git a/src/libstd/os/raw.rs b/src/libstd/os/raw.rs index 2de0448a5347f..9bab4af1a4a46 100644 --- a/src/libstd/os/raw.rs +++ b/src/libstd/os/raw.rs @@ -83,6 +83,7 @@ mod tests { } #[cfg(unix)] + #[test] fn unix() { { use os::unix::raw; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index fc9585d919069..241692f442546 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -346,8 +346,6 @@ mod imp { #[cfg(test)] mod tests { - use prelude::v1::*; - use sync::mpsc::channel; use rand::Rng; use super::OsRng; diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index d19bc5b617f84..b5b0f85669769 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -64,8 +64,6 @@ impl Rng for ReaderRng { #[cfg(test)] mod tests { - use prelude::v1::*; - use super::ReaderRng; use rand::Rng; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 1729d20da205c..04c7e746c6c52 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -23,7 +23,6 @@ use prelude::v1::*; use sys; -use usize; // Reexport some of our utilities which are expected by other crates. pub use self::util::{min_stack, running_on_valgrind}; @@ -51,15 +50,16 @@ mod libunwind; /// of exiting cleanly. pub const DEFAULT_ERROR_CODE: isize = 101; -#[cfg(any(windows, android))] +#[cfg(all(any(windows, android), not(test)))] const OS_DEFAULT_STACK_ESTIMATE: usize = 1 << 20; -#[cfg(all(unix, not(android)))] +#[cfg(all(unix, not(android), not(test)))] const OS_DEFAULT_STACK_ESTIMATE: usize = 2 * (1 << 20); #[cfg(not(test))] #[lang = "start"] fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { use prelude::v1::*; + use usize; use mem; use env; diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index 8f41646417367..549baa4156af8 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -158,7 +158,6 @@ mod tests { use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; use cell::RefCell; use sync::Arc; - use boxed; use thread; #[test] @@ -180,10 +179,11 @@ mod tests { #[test] fn is_mutex() { - let m = ReentrantMutex::new(RefCell::new(0)); + let m = Arc::new(ReentrantMutex::new(RefCell::new(0))); let lock = m.lock().unwrap(); - let handle = thread::scoped(|| { - let lock = m.lock().unwrap(); + let mc = m.clone(); + let handle = thread::spawn(move || { + let lock = mc.lock().unwrap(); assert_eq!(*lock.borrow(), 4950); }); for i in 0..100 { @@ -191,21 +191,20 @@ mod tests { *lock.borrow_mut() += i; } drop(lock); - drop(handle); + handle.join().unwrap(); } #[test] fn trylock_works() { - let m = ReentrantMutex::new(()); - let lock = m.try_lock().unwrap(); - let lock2 = m.try_lock().unwrap(); - { - thread::scoped(|| { - let lock = m.try_lock(); - assert!(lock.is_err()); - }); - } - let lock3 = m.try_lock().unwrap(); + let m = Arc::new(ReentrantMutex::new(())); + let _lock = m.try_lock().unwrap(); + let _lock2 = m.try_lock().unwrap(); + let mc = m.clone(); + thread::spawn(move || { + let lock = mc.try_lock(); + assert!(lock.is_err()); + }).join().unwrap(); + let _lock3 = m.try_lock().unwrap(); } pub struct Answer<'a>(pub ReentrantMutexGuard<'a, RefCell>); @@ -224,9 +223,8 @@ mod tests { *lock.borrow_mut() = 1; let lock2 = mc.lock().unwrap(); *lock.borrow_mut() = 2; - let answer = Answer(lock2); + let _answer = Answer(lock2); panic!("What the answer to my lifetimes dilemma is?"); - drop(answer); }).join(); assert!(result.is_err()); let r = m.lock().err().unwrap().into_inner(); diff --git a/src/libstd/sys/common/stack.rs b/src/libstd/sys/common/stack.rs index 11982ebc572e5..ba3f38a966bd6 100644 --- a/src/libstd/sys/common/stack.rs +++ b/src/libstd/sys/common/stack.rs @@ -216,6 +216,7 @@ pub unsafe fn record_sp_limit(limit: usize) { /// As with the setter, this function does not have a __morestack header and can /// therefore be called in a "we're out of stack" situation. #[inline(always)] +#[cfg(not(test))] pub unsafe fn get_sp_limit() -> usize { return target_get_sp_limit(); diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 695d0ddfaaf61..226026281368c 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -446,8 +446,7 @@ mod tests { use mem; use ptr; use libc; - use slice; - use sys::{self, c, cvt, pipe}; + use sys::{self, c, cvt}; #[cfg(not(target_os = "android"))] extern { diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index dbb7d3233bc39..3be1e44914052 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -769,12 +769,11 @@ mod tests { use prelude::v1::*; use any::Any; + use boxed::FnBox; use sync::mpsc::{channel, Sender}; use result; use super::{Builder}; use thread; - use thunk::Thunk; - use time::Duration; use u32; // !!! These tests are dangerous. If something is buggy, they will hang, !!! @@ -789,9 +788,9 @@ mod tests { #[test] fn test_named_thread() { - Builder::new().name("ada lovelace".to_string()).scoped(move|| { + Builder::new().name("ada lovelace".to_string()).spawn(move|| { assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); - }).unwrap().join(); + }).unwrap().join().unwrap(); } #[test] @@ -805,9 +804,9 @@ mod tests { #[test] fn test_join_success() { - assert!(thread::scoped(move|| -> String { + assert!(thread::spawn(move|| -> String { "Success!".to_string() - }).join() == "Success!"); + }).join().unwrap() == "Success!"); } #[test] @@ -821,6 +820,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_scoped_success() { let res = thread::scoped(move|| -> String { "Success!".to_string() @@ -830,12 +830,14 @@ mod tests { #[test] #[should_panic] + #[allow(deprecated)] fn test_scoped_panic() { thread::scoped(|| panic!()).join(); } #[test] #[should_panic] + #[allow(deprecated)] fn test_scoped_implicit_panic() { let _ = thread::scoped(|| panic!()); } @@ -874,7 +876,7 @@ mod tests { rx.recv().unwrap(); } - fn avoid_copying_the_body(spawnfn: F) where F: FnOnce(Thunk<'static>) { + fn avoid_copying_the_body(spawnfn: F) where F: FnOnce(Box) { let (tx, rx) = channel(); let x: Box<_> = box 1; @@ -921,7 +923,7 @@ mod tests { // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) const GENERATIONS: u32 = 16; - fn child_no(x: u32) -> Thunk<'static> { + fn child_no(x: u32) -> Box { return Box::new(move|| { if x < GENERATIONS { thread::spawn(move|| child_no(x+1)()); diff --git a/src/libstd/thread/scoped_tls.rs b/src/libstd/thread/scoped_tls.rs index 679902ec7abdb..d4b9d1d98f3b4 100644 --- a/src/libstd/thread/scoped_tls.rs +++ b/src/libstd/thread/scoped_tls.rs @@ -272,7 +272,6 @@ mod imp { #[cfg(test)] mod tests { use cell::Cell; - use prelude::v1::*; scoped_thread_local!(static FOO: u32);