Skip to content

Fix most warnings in tests #26626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ fn test_inspect() {
}

#[test]
#[allow(deprecated)]
fn test_unfoldr() {
fn count(st: &mut usize) -> Option<usize> {
if *st < 10 {
Expand Down Expand Up @@ -782,6 +783,7 @@ fn test_rposition_panic() {


#[cfg(test)]
#[allow(deprecated)]
fn check_randacc_iter<A, T>(a: T, len: usize) where
A: PartialEq,
T: Clone + RandomAccessIterator + Iterator<Item=A>,
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -884,6 +887,7 @@ fn test_random_access_skip() {
}

#[test]
#[allow(deprecated)]
fn test_random_access_inspect() {
let xs = [1, 2, 3, 4, 5];

Expand All @@ -897,6 +901,7 @@ fn test_random_access_inspect() {
}

#[test]
#[allow(deprecated)]
fn test_random_access_map() {
let xs = [1, 2, 3, 4, 5];

Expand Down Expand Up @@ -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::<Vec<_>>();
assert_eq!(&ys, &[5, 4, 3, 2, 1]);
}

#[test]
fn test_peekable_is_empty() {
let a = [1];
Expand Down Expand Up @@ -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));
Expand Down
1 change: 0 additions & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ impl FromInner<libc::in6_addr> for Ipv6Addr {
#[cfg(test)]
mod tests {
use prelude::v1::*;
use io;
use net::*;
use net::Ipv6MulticastScope::*;
use net::test::{tsa, sa6, sa4};
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))));
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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));
Expand Down
12 changes: 6 additions & 6 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1690,6 +1689,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_real_consts() {
use super::consts;

Expand Down
12 changes: 6 additions & 6 deletions src/libstd/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1646,6 +1645,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_real_consts() {
use super::consts;
let pi: f64 = consts::PI;
Expand Down
5 changes: 0 additions & 5 deletions src/libstd/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ pub fn test_num<T>(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;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ mod tests {
}

#[cfg(unix)]
#[test]
fn unix() {
{
use os::unix::raw;
Expand Down
2 changes: 0 additions & 2 deletions src/libstd/rand/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ mod imp {

#[cfg(test)]
mod tests {
use prelude::v1::*;

use sync::mpsc::channel;
use rand::Rng;
use super::OsRng;
Expand Down
2 changes: 0 additions & 2 deletions src/libstd/rand/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ impl<R: Read> Rng for ReaderRng<R> {

#[cfg(test)]
mod tests {
use prelude::v1::*;

use super::ReaderRng;
use rand::Rng;

Expand Down
6 changes: 3 additions & 3 deletions src/libstd/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 15 additions & 17 deletions src/libstd/sys/common/remutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ mod tests {
use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
use cell::RefCell;
use sync::Arc;
use boxed;
use thread;

#[test]
Expand All @@ -180,32 +179,32 @@ 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 {
let lock = m.lock().unwrap();
*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<u32>>);
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/common/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions src/libstd/sys/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading