Fix warnings when compiling stdlib with --test

This commit is contained in:
Florian Hahn 2015-12-18 13:29:49 +01:00
parent 27a1834ce5
commit e27cbeff37
26 changed files with 81 additions and 75 deletions

View File

@ -132,6 +132,7 @@ mod tests {
#[cfg_attr(any(windows,
target_os = "android", // FIXME #10379
target_env = "musl"), ignore)]
#[allow(deprecated)]
fn test_loading_cosine() {
// The math library does not need to be loaded since it is already
// statically linked in
@ -164,6 +165,7 @@ mod tests {
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd"))]
#[allow(deprecated)]
fn test_errors_do_not_crash() {
// Open /dev/null as a library to get an error, and make sure
// that only causes an error, and not a crash.

View File

@ -1281,7 +1281,6 @@ mod tests {
use io::{ErrorKind, SeekFrom};
use path::PathBuf;
use path::Path as Path2;
use os;
use rand::{self, StdRng, Rng};
use str;
@ -1410,8 +1409,8 @@ mod tests {
let message = "ten-four";
let mut read_mem = [0; 4];
let set_cursor = 4 as u64;
let mut tell_pos_pre_read;
let mut tell_pos_post_read;
let tell_pos_pre_read;
let tell_pos_post_read;
let tmpdir = tmpdir();
let filename = &tmpdir.join("file_rt_io_file_test_seeking.txt");
{

View File

@ -791,7 +791,7 @@ impl<W: Read + Write> Read for InternalBufWriter<W> {
mod tests {
use prelude::v1::*;
use io::prelude::*;
use io::{self, BufReader, BufWriter, Cursor, LineWriter, SeekFrom};
use io::{self, BufReader, BufWriter, LineWriter, SeekFrom};
use test;
/// A dummy reader intended at testing short-reads propagation.

View File

@ -377,7 +377,7 @@ mod test {
struct TestError;
impl fmt::Display for TestError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
Ok(())
}
}

View File

@ -1983,7 +1983,7 @@ mod tests {
b.iter(|| {
let mut lr = repeat(1).take(10000000);
let mut vec = Vec::with_capacity(1024);
super::read_to_end(&mut lr, &mut vec);
super::read_to_end(&mut lr, &mut vec)
});
}
}

View File

@ -199,6 +199,7 @@ mod tests {
}
#[test]
#[allow(deprecated)]
fn tee() {
let mut buf = [0; 10];
{
@ -209,6 +210,7 @@ mod tests {
}
#[test]
#[allow(deprecated)]
fn broadcast() {
let mut buf1 = [0; 10];
let mut buf2 = [0; 10];

View File

@ -468,9 +468,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]

View File

@ -527,7 +527,6 @@ impl FromInner<c::in6_addr> for Ipv6Addr {
#[cfg(test)]
mod tests {
use prelude::v1::*;
use io;
use net::*;
use net::Ipv6MulticastScope::*;
use net::test::{tsa, sa6, sa4};

View File

@ -319,7 +319,7 @@ mod tests {
use net::test::{next_test_ip4, next_test_ip6};
use sync::mpsc::channel;
use sys_common::AsInner;
use time::Duration;
use time::{Instant, Duration};
use thread;
fn each_ip(f: &mut FnMut(SocketAddr)) {
@ -929,6 +929,7 @@ mod tests {
t!(stream.set_write_timeout(None));
assert_eq!(None, t!(stream.write_timeout()));
drop(listener);
}
#[test]
@ -940,11 +941,11 @@ mod tests {
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));
let mut buf = [0; 10];
let wait = Duration::span(|| {
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(400));
let start = Instant::now();
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
assert!(start.elapsed() > Duration::from_millis(400));
drop(listener);
}
#[test]
@ -962,10 +963,10 @@ mod tests {
t!(stream.read(&mut buf));
assert_eq!(b"hello world", &buf[..]);
let wait = Duration::span(|| {
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(400));
let start = Instant::now();
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
assert!(start.elapsed() > Duration::from_millis(400));
drop(listener);
}
}

View File

@ -169,7 +169,7 @@ mod tests {
use net::test::{next_test_ip4, next_test_ip6};
use sync::mpsc::channel;
use sys_common::AsInner;
use time::Duration;
use time::{Instant, Duration};
use thread;
fn each_ip(f: &mut FnMut(SocketAddr, SocketAddr)) {
@ -370,22 +370,22 @@ 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];
let wait = Duration::span(|| {
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(400));
let start = Instant::now();
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
assert!(start.elapsed() > Duration::from_millis(400));
}
#[test]
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));
@ -394,10 +394,9 @@ mod tests {
t!(stream.recv_from(&mut buf));
assert_eq!(b"hello world", &buf[..]);
let wait = Duration::span(|| {
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(400));
let start = Instant::now();
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
assert!(start.elapsed() > Duration::from_millis(400));
}
}

View File

@ -15,11 +15,16 @@
#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]
#[cfg(not(test))]
use core::num;
#[cfg(not(test))]
use intrinsics;
#[cfg(not(test))]
use libc::c_int;
#[cfg(not(test))]
use num::FpCategory;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON};
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -15,9 +15,13 @@
#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]
#[cfg(not(test))]
use core::num;
#[cfg(not(test))]
use intrinsics;
#[cfg(not(test))]
use libc::c_int;
#[cfg(not(test))]
use num::FpCategory;
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -47,11 +47,6 @@ pub fn test_num<T>(ten: T, two: T) where
#[cfg(test)]
mod tests {
use super::*;
use i8;
use i16;
use i32;
use i64;
use isize;
use u8;
use u16;
use u32;

View File

@ -88,7 +88,8 @@ mod tests {
c_longlong c_ulonglong c_float c_double);
}
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "android")))]
#[test]
fn unix() {
{
use os::unix::raw;
@ -101,6 +102,7 @@ mod tests {
}
#[cfg(windows)]
#[test]
fn windows() {
use os::windows::raw;
}

View File

@ -381,8 +381,6 @@ mod imp {
#[cfg(test)]
mod tests {
use prelude::v1::*;
use sync::mpsc::channel;
use rand::Rng;
use super::OsRng;

View File

@ -63,8 +63,6 @@ impl<R: Read> Rng for ReaderRng<R> {
#[cfg(test)]
mod tests {
use prelude::v1::*;
use super::ReaderRng;
use rand::Rng;

View File

@ -22,13 +22,7 @@
issue = "0")]
#![doc(hidden)]
use borrow::ToOwned;
use mem;
use panic;
use sys;
use sys_common::thread_info::{self, NewThread};
use sys_common;
use thread::Thread;
// Reexport some of our utilities which are expected by other crates.
pub use sys_common::unwind::{begin_unwind, begin_unwind_fmt};
@ -41,6 +35,14 @@ pub use sys_common::unwind::imp::eh_frame_registry::*;
#[cfg(not(test))]
#[lang = "start"]
fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
use borrow::ToOwned;
use mem;
use panic;
use sys;
use sys_common;
use sys_common::thread_info::{self, NewThread};
use thread::Thread;
sys::init();
let failed = unsafe {

View File

@ -510,15 +510,15 @@ mod tests {
static M: StaticMutex = StaticMutex::new();
let g = M.lock().unwrap();
let (g, _no_timeout) = C.wait_timeout_ms(g, 1).unwrap();
let (g, _no_timeout) = C.wait_timeout(g, Duration::from_millis(1)).unwrap();
// spurious wakeups mean this isn't necessarily true
// assert!(!no_timeout);
let _t = thread::spawn(move || {
let _g = M.lock().unwrap();
C.notify_one();
});
let (g, no_timeout) = C.wait_timeout_ms(g, u32::MAX).unwrap();
assert!(no_timeout);
let (g, timeout_res) = C.wait_timeout(g, Duration::from_millis(u32::MAX as u64)).unwrap();
assert!(!timeout_res.timed_out());
drop(g);
unsafe { C.destroy(); M.destroy(); }
}

View File

@ -133,7 +133,7 @@ mod tests {
b.iter(|| {
let mut lr = repeat(1).take(10000000);
let mut vec = Vec::with_capacity(1024);
unsafe { read_to_end_uninitialized(&mut lr, &mut vec) };
unsafe { read_to_end_uninitialized(&mut lr, &mut vec) }
});
}
}

View File

@ -167,7 +167,6 @@ mod tests {
use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
use cell::RefCell;
use sync::Arc;
use boxed;
use thread;
#[test]
@ -208,13 +207,13 @@ mod tests {
fn trylock_works() {
let m = Arc::new(ReentrantMutex::new(()));
let m2 = m.clone();
let lock = m.try_lock().unwrap();
let lock2 = m.try_lock().unwrap();
let _lock = m.try_lock().unwrap();
let _lock2 = m.try_lock().unwrap();
thread::spawn(move || {
let lock = m2.try_lock();
assert!(lock.is_err());
}).join().unwrap();
let lock3 = m.try_lock().unwrap();
let _lock3 = m.try_lock().unwrap();
}
pub struct Answer<'a>(pub ReentrantMutexGuard<'a, RefCell<u32>>);
@ -233,9 +232,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();

View File

@ -1067,7 +1067,7 @@ mod tests {
#[test]
fn wtf8buf_show_str() {
let text = "a\té 💩\r";
let mut string = Wtf8Buf::from_str(text);
let string = Wtf8Buf::from_str(text);
assert_eq!(format!("{:?}", text), format!("{:?}", string));
}

View File

@ -45,7 +45,7 @@ pub mod thread_local;
pub mod time;
pub mod stdio;
#[cfg(not(target_os = "nacl"))]
#[cfg(not(any(target_os = "nacl", test)))]
pub fn init() {
use libc::signal;
// By default, some platforms will send a *signal* when an EPIPE error
@ -59,7 +59,8 @@ pub fn init() {
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0);
}
}
#[cfg(target_os = "nacl")]
#[cfg(all(target_os = "nacl", not(test)))]
pub fn init() { }
pub fn decode_error_kind(errno: i32) -> ErrorKind {

View File

@ -462,8 +462,7 @@ mod tests {
use mem;
use ptr;
use libc;
use slice;
use sys::{self, cvt, pipe};
use sys::{self, cvt};
macro_rules! t {
($e:expr) => {
@ -482,6 +481,8 @@ mod tests {
#[cfg(target_os = "android")]
unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int {
use slice;
let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::<libc::sigset_t>());
let bit = (signum - 1) as usize;
raw[bit / 8] |= 1 << (bit % 8);

View File

@ -7,11 +7,13 @@
// <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.
#![cfg_attr(test, allow(dead_code))]
use libc;
use self::imp::{make_handler, drop_handler};
pub use self::imp::{init, cleanup};
pub use self::imp::cleanup;
pub use self::imp::init;
pub struct Handler {
_data: *mut libc::c_void
@ -40,12 +42,11 @@ impl Drop for Handler {
target_os = "openbsd"))]
mod imp {
use super::Handler;
use sys_common::util::report_overflow;
use mem;
use ptr;
use libc::{sigaltstack, SIGSTKSZ};
use libc::{sigaction, SIGBUS, SIG_DFL,
SA_SIGINFO, SA_ONSTACK, sigaltstack,
SIGSTKSZ, sighandler_t};
SA_SIGINFO, SA_ONSTACK, sighandler_t};
use libc;
use libc::{mmap, munmap};
use libc::{SIGSEGV, PROT_READ, PROT_WRITE, MAP_PRIVATE, MAP_ANON};
@ -94,6 +95,8 @@ mod imp {
unsafe extern fn signal_handler(signum: libc::c_int,
info: *mut libc::siginfo_t,
_data: *mut libc::c_void) {
use sys_common::util::report_overflow;
let guard = thread_info::stack_guard().unwrap_or(0);
let addr = siginfo_si_addr(info) as usize;

View File

@ -830,14 +830,14 @@ mod tests {
fn test_park_timeout_unpark_before() {
for _ in 0..10 {
thread::current().unpark();
thread::park_timeout_ms(u32::MAX);
thread::park_timeout(Duration::from_millis(u32::MAX as u64));
}
}
#[test]
fn test_park_timeout_unpark_not_called() {
for _ in 0..10 {
thread::park_timeout_ms(10);
thread::park_timeout(Duration::from_millis(10));
}
}
@ -847,17 +847,17 @@ mod tests {
let th = thread::current();
let _guard = thread::spawn(move || {
super::sleep_ms(50);
super::sleep(Duration::from_millis(50));
th.unpark();
});
thread::park_timeout_ms(u32::MAX);
thread::park_timeout(Duration::from_millis(u32::MAX as u64));
}
}
#[test]
fn sleep_ms_smoke() {
thread::sleep_ms(2);
thread::sleep(Duration::from_millis(2));
}
// NOTE: the corresponding test for stderr is in run-pass/thread-stderr, due

View File

@ -173,7 +173,6 @@ impl Div<u32> for Duration {
#[cfg(test)]
mod tests {
use prelude::v1::*;
use super::Duration;
#[test]