From 470ae101d6e26a6ce07292b7fca6eaed527451c7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 29 Dec 2014 16:38:07 -0800 Subject: [PATCH] Test fixes and rebase conflicts --- src/libarena/lib.rs | 2 +- src/libcollections/lib.rs | 4 ++-- src/libcollections/str.rs | 10 ++-------- src/libcollections/string.rs | 2 +- src/libstd/c_str.rs | 2 +- src/libstd/collections/hash/map.rs | 2 +- src/libstd/io/process.rs | 1 + src/libstd/os.rs | 2 +- src/libstd/rt/backtrace.rs | 6 +++--- src/libstd/sync/mutex.rs | 8 +++++--- src/libstd/sync/rwlock.rs | 12 +++++++----- src/libstd/sys/common/net.rs | 4 ++-- src/libstd/sys/unix/pipe.rs | 2 +- src/libstd/sys/windows/c.rs | 1 - src/libstd/sys/windows/fs.rs | 4 ++-- src/libstd/sys/windows/os.rs | 11 ++++++----- src/libstd/sys/windows/tty.rs | 4 ++-- src/test/compile-fail/issue-7364.rs | 1 - src/test/compile-fail/mut-not-freeze.rs | 1 - 19 files changed, 38 insertions(+), 41 deletions(-) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 1f4df1fd0a5..b0fa5434a14 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -412,7 +412,7 @@ impl TypedArenaChunk { let size = calculate_size::(self.capacity); deallocate(self as *mut TypedArenaChunk as *mut u8, size, mem::min_align_of::>()); - if next.is_not_null() { + if !next.is_null() { let capacity = (*next).capacity; (*next).destroy(capacity); } diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 363d30abd03..fe9d8de440a 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -114,14 +114,14 @@ mod prelude { pub use core::ops::{Drop, Fn, FnMut, FnOnce}; pub use core::option::Option; pub use core::option::Option::{Some, None}; - pub use core::ptr::RawPtr; + pub use core::ptr::PtrExt; pub use core::result::Result; pub use core::result::Result::{Ok, Err}; // in core and collections (may differ). pub use slice::{PartialEqSliceExt, OrdSliceExt}; pub use slice::{AsSlice, SliceExt}; - pub use str::{from_str, Str}; + pub use str::{from_str, Str, StrExt}; // from other crates. pub use alloc::boxed::Box; diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index fdc52ab8eb0..7c7a7e19a2f 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1770,15 +1770,9 @@ mod tests { use core::default::Default; use core::iter::AdditiveIterator; - use super::{eq_slice, from_utf8, is_utf8, is_utf16, raw}; - use super::truncate_utf16_at_nul; + use super::{from_utf8, is_utf8, raw}; use super::MaybeOwned::{Owned, Slice}; - use std::slice::{AsSlice, SliceExt}; - use string::{String, ToString}; - use vec::Vec; - use slice::CloneSliceExt; - - use unicode::char::UnicodeChar; + use super::Utf8Error; #[test] fn test_le() { diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 51ad0b52b81..c6c19cae75f 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1082,7 +1082,7 @@ mod tests { use prelude::*; use test::Bencher; - use str::{StrExt, Utf8Error}; + use str::Utf8Error; use str; use super::as_string; diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 39c57b99b36..f28abcc10cf 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -538,7 +538,7 @@ pub unsafe fn from_c_multistring(buf: *const libc::c_char, mod tests { use super::*; use prelude::{spawn, Some, None, Option, FnOnce, ToString, CloneSliceExt}; - use prelude::{Clone, RawPtr, Iterator, SliceExt, StrExt}; + use prelude::{Clone, PtrExt, Iterator, SliceExt, StrExt}; use ptr; use thread::Thread; use libc; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index c62ca6f5929..7b7473b2c99 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -278,7 +278,7 @@ fn test_resize_policy() { /// /// impl Viking { /// /// Create a new Viking. -/// pub fn new(name: &str, country: &str) -> Viking { +/// fn new(name: &str, country: &str) -> Viking { /// Viking { name: name.to_string(), country: country.to_string() } /// } /// } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 9e0c76e4e79..b127507f048 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -1207,6 +1207,7 @@ mod tests { #[test] #[cfg(windows)] fn env_map_keys_ci() { + use c_str::ToCStr; use super::EnvKey; let mut cmd = Command::new(""); cmd.env("path", "foo"); diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 049d97798e4..989f44f7b8e 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -731,7 +731,7 @@ fn real_args() -> Vec { let ptr = ptr as *const u16; let buf = slice::from_raw_buf(&ptr, len); let opt_s = String::from_utf16(sys::os::truncate_utf16_at_nul(buf)); - opt_s.expect("CommandLineToArgvW returned invalid UTF-16") + opt_s.ok().expect("CommandLineToArgvW returned invalid UTF-16") }); unsafe { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 775e9bb526f..3eeb0ad3968 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -60,19 +60,19 @@ mod test { t!("_ZN4$UP$E", "Box"); t!("_ZN8$UP$testE", "Boxtest"); t!("_ZN8$UP$test4foobE", "Boxtest::foob"); - t!("_ZN8$x20test4foobE", " test::foob"); + t!("_ZN10$u{20}test4foobE", " test::foob"); } #[test] fn demangle_many_dollars() { - t!("_ZN12test$x20test4foobE", "test test::foob"); + t!("_ZN14test$u{20}test4foobE", "test test::foob"); t!("_ZN12test$UP$test4foobE", "testBoxtest::foob"); } #[test] fn demangle_windows() { t!("ZN4testE", "test"); - t!("ZN12test$x20test4foobE", "test test::foob"); + t!("ZN14test$u{20}test4foobE", "test test::foob"); t!("ZN12test$UP$test4foobE", "testBoxtest::foob"); } } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 32c2c67152f..52004bb4a8f 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -234,7 +234,9 @@ impl Drop for Mutex { } } -static DUMMY: UnsafeCell<()> = UnsafeCell { value: () }; +struct Dummy(UnsafeCell<()>); +unsafe impl Sync for Dummy {} +static DUMMY: Dummy = Dummy(UnsafeCell { value: () }); impl StaticMutex { /// Acquires this lock, see `Mutex::lock` @@ -242,7 +244,7 @@ impl StaticMutex { #[unstable = "may be merged with Mutex in the future"] pub fn lock(&'static self) -> LockResult> { unsafe { self.lock.lock() } - MutexGuard::new(self, &DUMMY) + MutexGuard::new(self, &DUMMY.0) } /// Attempts to grab this lock, see `Mutex::try_lock` @@ -250,7 +252,7 @@ impl StaticMutex { #[unstable = "may be merged with Mutex in the future"] pub fn try_lock(&'static self) -> TryLockResult> { if unsafe { self.lock.try_lock() } { - Ok(try!(MutexGuard::new(self, &DUMMY))) + Ok(try!(MutexGuard::new(self, &DUMMY.0))) } else { Err(TryLockError::WouldBlock) } diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 1b7a7f3f323..7f3c77c97ad 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -233,7 +233,9 @@ impl Drop for RWLock { } } -static DUMMY: UnsafeCell<()> = UnsafeCell { value: () }; +struct Dummy(UnsafeCell<()>); +unsafe impl Sync for Dummy {} +static DUMMY: Dummy = Dummy(UnsafeCell { value: () }); impl StaticRWLock { /// Locks this rwlock with shared read access, blocking the current thread @@ -244,7 +246,7 @@ impl StaticRWLock { #[unstable = "may be merged with RWLock in the future"] pub fn read(&'static self) -> LockResult> { unsafe { self.lock.read() } - RWLockReadGuard::new(self, &DUMMY) + RWLockReadGuard::new(self, &DUMMY.0) } /// Attempt to acquire this lock with shared read access. @@ -255,7 +257,7 @@ impl StaticRWLock { pub fn try_read(&'static self) -> TryLockResult> { if unsafe { self.lock.try_read() } { - Ok(try!(RWLockReadGuard::new(self, &DUMMY))) + Ok(try!(RWLockReadGuard::new(self, &DUMMY.0))) } else { Err(TryLockError::WouldBlock) } @@ -269,7 +271,7 @@ impl StaticRWLock { #[unstable = "may be merged with RWLock in the future"] pub fn write(&'static self) -> LockResult> { unsafe { self.lock.write() } - RWLockWriteGuard::new(self, &DUMMY) + RWLockWriteGuard::new(self, &DUMMY.0) } /// Attempt to lock this rwlock with exclusive write access. @@ -280,7 +282,7 @@ impl StaticRWLock { pub fn try_write(&'static self) -> TryLockResult> { if unsafe { self.lock.try_write() } { - Ok(try!(RWLockWriteGuard::new(self, &DUMMY))) + Ok(try!(RWLockWriteGuard::new(self, &DUMMY.0))) } else { Err(TryLockError::WouldBlock) } diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 793e81e1ab5..7a09137a225 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -669,7 +669,7 @@ impl TcpStream { fn lock_nonblocking<'a>(&'a self) -> Guard<'a> { let ret = Guard { fd: self.fd(), - guard: self.inner.lock.lock(), + guard: self.inner.lock.lock().unwrap(), }; assert!(set_nonblocking(self.fd(), true).is_ok()); ret @@ -808,7 +808,7 @@ impl UdpSocket { fn lock_nonblocking<'a>(&'a self) -> Guard<'a> { let ret = Guard { fd: self.fd(), - guard: self.inner.lock.lock(), + guard: self.inner.lock.lock().unwrap(), }; assert!(set_nonblocking(self.fd(), true).is_ok()); ret diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index f1b078b4e80..868b460aa5e 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -145,7 +145,7 @@ impl UnixStream { fn lock_nonblocking<'a>(&'a self) -> Guard<'a> { let ret = Guard { fd: self.fd(), - guard: unsafe { self.inner.lock.lock() }, + guard: unsafe { self.inner.lock.lock().unwrap() }, }; assert!(set_nonblocking(self.fd(), true).is_ok()); ret diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index d1cb91bcdb3..06259d61fcb 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -131,7 +131,6 @@ extern "system" { pub mod compat { use intrinsics::{atomic_store_relaxed, transmute}; - use iter::IteratorExt; use libc::types::os::arch::extra::{LPCWSTR, HMODULE, LPCSTR, LPVOID}; use prelude::*; diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 15eddd569be..3ad439078b9 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -265,8 +265,8 @@ pub fn readdir(p: &Path) -> IoResult> { { let filename = os::truncate_utf16_at_nul(&wfd.cFileName); match String::from_utf16(filename) { - Some(filename) => paths.push(Path::new(filename)), - None => { + Ok(filename) => paths.push(Path::new(filename)), + Err(..) => { assert!(libc::FindClose(find_handle) != 0); return Err(IoError { kind: io::InvalidInput, diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index e007b46b261..fa08290a888 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -99,8 +99,9 @@ pub fn error_string(errnum: i32) -> String { let msg = String::from_utf16(truncate_utf16_at_nul(&buf)); match msg { - Some(msg) => format!("OS Error {}: {}", errnum, msg), - None => format!("OS Error {} (FormatMessageW() returned invalid UTF-16)", errnum), + Ok(msg) => format!("OS Error {}: {}", errnum, msg), + Err(..) => format!("OS Error {} (FormatMessageW() returned \ + invalid UTF-16)", errnum), } } } @@ -147,7 +148,7 @@ pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD) -> Option IoResult { } match String::from_utf16(truncate_utf16_at_nul(&buf)) { - Some(ref cwd) => Ok(Path::new(cwd)), - None => Err(IoError { + Ok(ref cwd) => Ok(Path::new(cwd)), + Err(..) => Err(IoError { kind: OtherIoError, desc: "GetCurrentDirectoryW returned invalid UTF-16", detail: None, diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index f793de5bb57..99292b3b44b 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -101,8 +101,8 @@ impl TTY { }; utf16.truncate(num as uint); let utf8 = match String::from_utf16(utf16.as_slice()) { - Some(utf8) => utf8.into_bytes(), - None => return Err(invalid_encoding()), + Ok(utf8) => utf8.into_bytes(), + Err(..) => return Err(invalid_encoding()), }; self.utf8 = MemReader::new(utf8); } diff --git a/src/test/compile-fail/issue-7364.rs b/src/test/compile-fail/issue-7364.rs index ab5ba296652..77836143f27 100644 --- a/src/test/compile-fail/issue-7364.rs +++ b/src/test/compile-fail/issue-7364.rs @@ -16,6 +16,5 @@ static boxed: Box> = box RefCell::new(0); //~^ ERROR statics are not allowed to have custom pointers //~| ERROR: the trait `core::kinds::Sync` is not implemented for the type //~| ERROR: the trait `core::kinds::Sync` is not implemented for the type -//~| ERROR: the trait `core::kinds::Sync` is not implemented for the type fn main() { } diff --git a/src/test/compile-fail/mut-not-freeze.rs b/src/test/compile-fail/mut-not-freeze.rs index 4b058f6fdb3..95ebb8bd882 100644 --- a/src/test/compile-fail/mut-not-freeze.rs +++ b/src/test/compile-fail/mut-not-freeze.rs @@ -17,5 +17,4 @@ fn main() { f(x); //~^ ERROR `core::kinds::Sync` is not implemented //~^^ ERROR `core::kinds::Sync` is not implemented - //~^^^ ERROR `core::kinds::Sync` is not implemented }