summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/errno.rs6
-rw-r--r--src/fcntl.rs3
-rw-r--r--src/lib.rs20
-rw-r--r--src/mqueue.rs12
-rw-r--r--src/pty.rs22
-rw-r--r--src/sys/aio.rs36
-rw-r--r--src/sys/event.rs4
-rw-r--r--src/sys/ioctl/mod.rs2
-rw-r--r--src/sys/ioctl/platform/bsd.rs6
-rw-r--r--src/sys/pthread.rs6
-rw-r--r--src/sys/ptrace.rs2
-rw-r--r--src/sys/signal.rs23
-rw-r--r--src/sys/signalfd.rs3
-rw-r--r--src/sys/socket/addr.rs35
-rw-r--r--src/sys/socket/mod.rs18
-rw-r--r--src/sys/stat.rs16
-rw-r--r--src/sys/termios.rs2
-rw-r--r--src/sys/uio.rs12
-rw-r--r--src/sys/utsname.rs15
-rw-r--r--src/sys/wait.rs13
-rw-r--r--src/unistd.rs8
-rw-r--r--test/sys/test_aio.rs110
-rw-r--r--test/sys/test_aio_drop.rs4
-rw-r--r--test/sys/test_ioctl.rs74
-rw-r--r--test/sys/test_ptrace.rs17
-rw-r--r--test/sys/test_signal.rs2
-rw-r--r--test/sys/test_signalfd.rs2
-rw-r--r--test/sys/test_socket.rs2
-rw-r--r--test/sys/test_sockopt.rs2
-rw-r--r--test/sys/test_termios.rs2
-rw-r--r--test/sys/test_uio.rs19
-rw-r--r--test/sys/test_wait.rs25
-rw-r--r--test/test.rs2
-rw-r--r--test/test_fcntl.rs8
-rw-r--r--test/test_mount.rs6
-rw-r--r--test/test_mq.rs10
-rw-r--r--test/test_net.rs4
-rw-r--r--test/test_pty.rs4
-rw-r--r--test/test_ptymaster_drop.rs2
-rw-r--r--test/test_sendfile.rs4
-rw-r--r--test/test_stat.rs62
-rw-r--r--test/test_unistd.rs23
42 files changed, 299 insertions, 349 deletions
diff --git a/src/errno.rs b/src/errno.rs
index 1f88ec78..2d0ad6c9 100644
--- a/src/errno.rs
+++ b/src/errno.rs
@@ -675,7 +675,6 @@ mod consts {
use self::Errno::*;
match e {
- 0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
@@ -940,7 +939,6 @@ mod consts {
use self::Errno::*;
match e {
- 0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
@@ -1168,7 +1166,6 @@ mod consts {
use self::Errno::*;
match e {
- 0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
@@ -1391,7 +1388,6 @@ mod consts {
use self::Errno::*;
match e {
- 0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
@@ -1607,7 +1603,6 @@ mod consts {
use self::Errno::*;
match e {
- 0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
@@ -1819,7 +1814,6 @@ mod consts {
use self::Errno::*;
match e {
- 0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 5abf65ac..fa96491f 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -152,8 +152,7 @@ pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: M
Errno::result(fd)
}
-fn wrap_readlink_result<'a>(buffer: &'a mut[u8], res: ssize_t)
- -> Result<&'a OsStr> {
+fn wrap_readlink_result(buffer: &mut[u8], res: ssize_t) -> Result<&OsStr> {
match Errno::result(res) {
Err(err) => Err(err),
Ok(len) => {
diff --git a/src/lib.rs b/src/lib.rs
index 8ddfad9b..8a63c072 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -128,22 +128,22 @@ impl From<std::string::FromUtf8Error> for Error {
impl error::Error for Error {
fn description(&self) -> &str {
- match self {
- &Error::InvalidPath => "Invalid path",
- &Error::InvalidUtf8 => "Invalid UTF-8 string",
- &Error::UnsupportedOperation => "Unsupported Operation",
- &Error::Sys(ref errno) => errno.desc(),
+ match *self {
+ Error::InvalidPath => "Invalid path",
+ Error::InvalidUtf8 => "Invalid UTF-8 string",
+ Error::UnsupportedOperation => "Unsupported Operation",
+ Error::Sys(ref errno) => errno.desc(),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- match self {
- &Error::InvalidPath => write!(f, "Invalid path"),
- &Error::InvalidUtf8 => write!(f, "Invalid UTF-8 string"),
- &Error::UnsupportedOperation => write!(f, "Unsupported Operation"),
- &Error::Sys(errno) => write!(f, "{:?}: {}", errno, errno.desc()),
+ match *self {
+ Error::InvalidPath => write!(f, "Invalid path"),
+ Error::InvalidUtf8 => write!(f, "Invalid UTF-8 string"),
+ Error::UnsupportedOperation => write!(f, "Unsupported Operation"),
+ Error::Sys(errno) => write!(f, "{:?}: {}", errno, errno.desc()),
}
}
}
diff --git a/src/mqueue.rs b/src/mqueue.rs
index 89bb2784..e578d5e7 100644
--- a/src/mqueue.rs
+++ b/src/mqueue.rs
@@ -66,7 +66,7 @@ impl MqAttr {
/// Open a message queue
///
-/// See also [mq_open(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html)
+/// See also [`mq_open(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html)
pub fn mq_open(name: &CString,
oflag: MQ_OFlag,
mode: Mode,
@@ -86,7 +86,7 @@ pub fn mq_open(name: &CString,
/// Remove a message queue
///
-/// See also [mq_unlink(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html)
+/// See also [`mq_unlink(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html)
pub fn mq_unlink(name: &CString) -> Result<()> {
let res = unsafe { libc::mq_unlink(name.as_ptr()) };
Errno::result(res).map(drop)
@@ -94,7 +94,7 @@ pub fn mq_unlink(name: &CString) -> Result<()> {
/// Close a message queue
///
-/// See also [mq_close(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html)
+/// See also [`mq_close(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html)
pub fn mq_close(mqdes: mqd_t) -> Result<()> {
let res = unsafe { libc::mq_close(mqdes) };
Errno::result(res).map(drop)
@@ -102,7 +102,7 @@ pub fn mq_close(mqdes: mqd_t) -> Result<()> {
/// Receive a message from a message queue
///
-/// See also [mq_receive(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html)
+/// See also [`mq_receive(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html)
pub fn mq_receive(mqdes: mqd_t, message: &mut [u8], msg_prio: &mut u32) -> Result<usize> {
let len = message.len() as size_t;
let res = unsafe {
@@ -116,7 +116,7 @@ pub fn mq_receive(mqdes: mqd_t, message: &mut [u8], msg_prio: &mut u32) -> Resul
/// Send a message to a message queue
///
-/// See also [mq_send(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html)
+/// See also [`mq_send(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html)
pub fn mq_send(mqdes: mqd_t, message: &[u8], msq_prio: u32) -> Result<()> {
let res = unsafe {
libc::mq_send(mqdes,
@@ -129,7 +129,7 @@ pub fn mq_send(mqdes: mqd_t, message: &[u8], msq_prio: u32) -> Result<()> {
/// Get message queue attributes
///
-/// See also [mq_getattr(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html)
+/// See also [`mq_getattr(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html)
pub fn mq_getattr(mqd: mqd_t) -> Result<MqAttr> {
let mut attr = unsafe { mem::uninitialized::<libc::mq_attr>() };
let res = unsafe { libc::mq_getattr(mqd, &mut attr) };
diff --git a/src/pty.rs b/src/pty.rs
index d526ed17..ea0e543d 100644
--- a/src/pty.rs
+++ b/src/pty.rs
@@ -62,21 +62,21 @@ impl Drop for PtyMaster {
}
/// Grant access to a slave pseudoterminal (see
-/// [grantpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/grantpt.html))
+/// [`grantpt(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/grantpt.html))
///
/// `grantpt()` changes the mode and owner of the slave pseudoterminal device corresponding to the
/// master pseudoterminal referred to by `fd`. This is a necessary step towards opening the slave.
#[inline]
pub fn grantpt(fd: &PtyMaster) -> Result<()> {
if unsafe { libc::grantpt(fd.as_raw_fd()) } < 0 {
- return Err(Error::last().into());
+ return Err(Error::last());
}
Ok(())
}
/// Open a pseudoterminal device (see
-/// [posix_openpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html))
+/// [`posix_openpt(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html))
///
/// `posix_openpt()` returns a file descriptor to an existing unused pseuterminal master device.
///
@@ -116,14 +116,14 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
};
if fd < 0 {
- return Err(Error::last().into());
+ return Err(Error::last());
}
Ok(PtyMaster(fd))
}
/// Get the name of the slave pseudoterminal (see
-/// [ptsname(3)](http://man7.org/linux/man-pages/man3/ptsname.3.html))
+/// [`ptsname(3)`](http://man7.org/linux/man-pages/man3/ptsname.3.html))
///
/// `ptsname()` returns the name of the slave pseudoterminal device corresponding to the master
/// referred to by `fd`.
@@ -142,7 +142,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
pub unsafe fn ptsname(fd: &PtyMaster) -> Result<String> {
let name_ptr = libc::ptsname(fd.as_raw_fd());
if name_ptr.is_null() {
- return Err(Error::last().into());
+ return Err(Error::last());
}
let name = CStr::from_ptr(name_ptr);
@@ -150,7 +150,7 @@ pub unsafe fn ptsname(fd: &PtyMaster) -> Result<String> {
}
/// Get the name of the slave pseudoterminal (see
-/// [ptsname(3)](http://man7.org/linux/man-pages/man3/ptsname.3.html))
+/// [`ptsname(3)`](http://man7.org/linux/man-pages/man3/ptsname.3.html))
///
/// `ptsname_r()` returns the name of the slave pseudoterminal device corresponding to the master
/// referred to by `fd`. This is the threadsafe version of `ptsname()`, but it is not part of the
@@ -164,7 +164,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
let mut name_buf = vec![0u8; 64];
let name_buf_ptr = name_buf.as_mut_ptr() as *mut libc::c_char;
if unsafe { libc::ptsname_r(fd.as_raw_fd(), name_buf_ptr, name_buf.capacity()) } != 0 {
- return Err(Error::last().into());
+ return Err(Error::last());
}
// Find the first null-character terminating this string. This is guaranteed to succeed if the
@@ -177,7 +177,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
}
/// Unlock a pseudoterminal master/slave pseudoterminal pair (see
-/// [unlockpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlockpt.html))
+/// [`unlockpt(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlockpt.html))
///
/// `unlockpt()` unlocks the slave pseudoterminal device corresponding to the master pseudoterminal
/// referred to by `fd`. This must be called before trying to open the slave side of a
@@ -185,7 +185,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
#[inline]
pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
if unsafe { libc::unlockpt(fd.as_raw_fd()) } < 0 {
- return Err(Error::last().into());
+ return Err(Error::last());
}
Ok(())
@@ -194,7 +194,7 @@ pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
/// Create a new pseudoterminal, returning the slave and master file descriptors
/// in `OpenptyResult`
-/// (see [openpty](http://man7.org/linux/man-pages/man3/openpty.3.html)).
+/// (see [`openpty`](http://man7.org/linux/man-pages/man3/openpty.3.html)).
///
/// If `winsize` is not `None`, the window size of the slave will be set to
/// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's
diff --git a/src/sys/aio.rs b/src/sys/aio.rs
index 909b59d7..d85ecfa1 100644
--- a/src/sys/aio.rs
+++ b/src/sys/aio.rs
@@ -111,9 +111,12 @@ impl<'a> AioCb<'a> {
a.aio_nbytes = 0;
a.aio_buf = null_mut();
- let aiocb = AioCb { aiocb: a, mutable: false, in_progress: false,
- keeper: Keeper::none};
- aiocb
+ AioCb {
+ aiocb: a,
+ mutable: false,
+ in_progress: false,
+ keeper: Keeper::none
+ }
}
/// Constructs a new `AioCb`.
@@ -136,9 +139,12 @@ impl<'a> AioCb<'a> {
a.aio_buf = buf.as_ptr() as *mut c_void;
a.aio_lio_opcode = opcode as libc::c_int;
- let aiocb = AioCb { aiocb: a, mutable: true, in_progress: false,
- keeper: Keeper::phantom(PhantomData)};
- aiocb
+ AioCb {
+ aiocb: a,
+ mutable: true,
+ in_progress: false,
+ keeper: Keeper::phantom(PhantomData)
+ }
}
/// Constructs a new `AioCb`.
@@ -164,9 +170,12 @@ impl<'a> AioCb<'a> {
a.aio_buf = buf.as_ptr() as *mut c_void;
a.aio_lio_opcode = opcode as libc::c_int;
- let aiocb = AioCb{ aiocb: a, mutable: true, in_progress: false,
- keeper: Keeper::boxed(buf)};
- aiocb
+ AioCb {
+ aiocb: a,
+ mutable: true,
+ in_progress: false,
+ keeper: Keeper::boxed(buf)
+ }
}
/// Like `from_mut_slice`, but works on constant slices rather than
@@ -195,9 +204,12 @@ impl<'a> AioCb<'a> {
assert!(opcode != LioOpcode::LIO_READ, "Can't read into an immutable buffer");
a.aio_lio_opcode = opcode as libc::c_int;
- let aiocb = AioCb { aiocb: a, mutable: false, in_progress: false,
- keeper: Keeper::none};
- aiocb
+ AioCb {
+ aiocb: a,
+ mutable: false,
+ in_progress: false,
+ keeper: Keeper::none
+ }
}
fn common_init(fd: RawFd, prio: libc::c_int,
diff --git a/src/sys/event.rs b/src/sys/event.rs
index e63fe502..4d5d1880 100644
--- a/src/sys/event.rs
+++ b/src/sys/event.rs
@@ -312,13 +312,13 @@ pub fn ev_set(ev: &mut KEvent,
fn test_struct_kevent() {
let udata : intptr_t = 12345;
- let expected = libc::kevent{ident: 0xdeadbeef,
+ let expected = libc::kevent{ident: 0xdead_beef,
filter: libc::EVFILT_READ,
flags: libc::EV_ONESHOT | libc::EV_ADD,
fflags: libc::NOTE_CHILD | libc::NOTE_EXIT,
data: 0x1337,
udata: udata as type_of_udata};
- let actual = KEvent::new(0xdeadbeef,
+ let actual = KEvent::new(0xdead_beef,
EventFilter::EVFILT_READ,
EventFlag::EV_ONESHOT | EventFlag::EV_ADD,
FilterFlag::NOTE_CHILD | FilterFlag::NOTE_EXIT,
diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs
index 4169920b..44822e4f 100644
--- a/src/sys/ioctl/mod.rs
+++ b/src/sys/ioctl/mod.rs
@@ -255,7 +255,7 @@ macro_rules! convert_ioctl_res {
);
}
-/// Generates ioctl functions. See [::sys::ioctl](sys/ioctl/index.html).
+/// Generates ioctl functions. See [`::sys::ioctl`](sys/ioctl/index.html).
#[macro_export]
macro_rules! ioctl {
($(#[$attr:meta])* bad none $name:ident with $nr:expr) => (
diff --git a/src/sys/ioctl/platform/bsd.rs b/src/sys/ioctl/platform/bsd.rs
index ea39da3d..a36808d7 100644
--- a/src/sys/ioctl/platform/bsd.rs
+++ b/src/sys/ioctl/platform/bsd.rs
@@ -5,11 +5,11 @@ pub type ioctl_num_type = ::libc::c_ulong;
mod consts {
use ::sys::ioctl::platform::ioctl_num_type;
#[doc(hidden)]
- pub const VOID: ioctl_num_type = 0x20000000;
+ pub const VOID: ioctl_num_type = 0x2000_0000;
#[doc(hidden)]
- pub const OUT: ioctl_num_type = 0x40000000;
+ pub const OUT: ioctl_num_type = 0x4000_0000;
#[doc(hidden)]
- pub const IN: ioctl_num_type = 0x80000000;
+ pub const IN: ioctl_num_type = 0x8000_0000;
#[doc(hidden)]
pub const INOUT: ioctl_num_type = (IN|OUT);
#[doc(hidden)]
diff --git a/src/sys/pthread.rs b/src/sys/pthread.rs
index d533946b..a4d98250 100644
--- a/src/sys/pthread.rs
+++ b/src/sys/pthread.rs
@@ -3,10 +3,10 @@ use libc::{self, pthread_t};
pub type Pthread = pthread_t;
/// Obtain ID of the calling thread (see
-/// [pthread_self(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html)
+/// [`pthread_self(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html)
///
-/// The thread ID returned by pthread_self() is not the same thing as
-/// the kernel thread ID returned by a call to gettid(2).
+/// The thread ID returned by `pthread_self()` is not the same thing as
+/// the kernel thread ID returned by a call to `gettid(2)`.
#[inline]
pub fn pthread_self() -> Pthread {
unsafe { libc::pthread_self() }
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs
index e2b153d8..8fb8f823 100644
--- a/src/sys/ptrace.rs
+++ b/src/sys/ptrace.rs
@@ -151,7 +151,7 @@ fn ptrace_peek(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void)
}
/// Function for ptrace requests that return values from the data field.
-/// Some ptrace get requests populate structs or larger elements than c_long
+/// Some ptrace get requests populate structs or larger elements than `c_long`
/// and therefore use the data field to return values. This function handles these
/// requests.
fn ptrace_get_data<T>(request: Request, pid: Pid) -> Result<T> {
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index f82e4502..d295abcc 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -34,7 +34,7 @@ libc_enum!{
SIGPIPE,
SIGALRM,
SIGTERM,
- #[cfg(all(any(target_os = "android", target_os = "emscripten", target_os = "linux"),
+ #[cfg(all(any(target_os = "android", target_os = "emscripten", target_os = "linux"),
not(any(target_arch = "mips", target_arch = "mips64"))))]
SIGSTKFLT,
SIGCHLD,
@@ -191,9 +191,10 @@ impl Signal {
// implemented, we'll replace this function.
#[inline]
pub fn from_c_int(signum: libc::c_int) -> Result<Signal> {
- match 0 < signum && signum < NSIG {
- true => Ok(unsafe { mem::transmute(signum) }),
- false => Err(Error::invalid_argument()),
+ if 0 < signum && signum < NSIG {
+ Ok(unsafe { mem::transmute(signum) })
+ } else {
+ Err(Error::invalid_argument())
}
}
}
@@ -423,8 +424,8 @@ pub unsafe fn sigaction(signal: Signal, sigaction: &SigAction) -> Result<SigActi
///
/// If both `set` and `oldset` is None, this function is a no-op.
///
-/// For more information, visit the [pthread_sigmask](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html),
-/// or [sigprocmask](http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigprocmask.html) man pages.
+/// For more information, visit the [`pthread_sigmask`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html),
+/// or [`sigprocmask`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigprocmask.html) man pages.
pub fn pthread_sigmask(how: SigmaskHow,
set: Option<&SigSet>,
oldset: Option<&mut SigSet>) -> Result<()> {
@@ -435,9 +436,9 @@ pub fn pthread_sigmask(how: SigmaskHow,
let res = unsafe {
// if set or oldset is None, pass in null pointers instead
libc::pthread_sigmask(how as libc::c_int,
- set.map_or_else(|| ptr::null::<libc::sigset_t>(),
+ set.map_or_else(ptr::null::<libc::sigset_t>,
|s| &s.sigset as *const libc::sigset_t),
- oldset.map_or_else(|| ptr::null_mut::<libc::sigset_t>(),
+ oldset.map_or_else(ptr::null_mut::<libc::sigset_t>,
|os| &mut os.sigset as *mut libc::sigset_t))
};
@@ -560,8 +561,8 @@ mod sigevent {
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
fn set_tid(sev: &mut libc::sigevent, sigev_notify: &SigevNotify) {
- sev.sigev_notify_thread_id = match sigev_notify {
- &SigevNotify::SigevThreadId { thread_id, .. } => thread_id,
+ sev.sigev_notify_thread_id = match *sigev_notify {
+ SigevNotify::SigevThreadId { thread_id, .. } => thread_id,
_ => 0 as type_of_thread_id
};
}
@@ -599,7 +600,7 @@ mod sigevent {
impl<'a> From<&'a libc::sigevent> for SigEvent {
fn from(sigevent: &libc::sigevent) -> Self {
- SigEvent{ sigevent: sigevent.clone() }
+ SigEvent{ sigevent: *sigevent }
}
}
}
diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs
index 0da9187e..52027d36 100644
--- a/src/sys/signalfd.rs
+++ b/src/sys/signalfd.rs
@@ -127,8 +127,7 @@ impl Iterator for SignalFd {
fn next(&mut self) -> Option<Self::Item> {
match self.read_signal() {
Ok(Some(sig)) => Some(sig),
- Ok(None) => None,
- Err(..) => None,
+ Ok(None) | Err(_) => None,
}
}
}
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index b479c9cd..dd2ae17d 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -222,7 +222,7 @@ impl AddressFamily {
}
}
-#[derive(Copy)]
+#[derive(Clone, Copy)]
pub enum InetAddr {
V4(libc::sockaddr_in),
V6(libc::sockaddr_in6),
@@ -348,12 +348,6 @@ impl hash::Hash for InetAddr {
}
}
-impl Clone for InetAddr {
- fn clone(&self) -> InetAddr {
- *self
- }
-}
-
impl fmt::Display for InetAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
@@ -421,7 +415,7 @@ impl fmt::Display for IpAddr {
*
*/
-#[derive(Copy)]
+#[derive(Clone, Copy)]
pub struct Ipv4Addr(pub libc::in_addr);
impl Ipv4Addr {
@@ -469,12 +463,6 @@ impl hash::Hash for Ipv4Addr {
}
}
-impl Clone for Ipv4Addr {
- fn clone(&self) -> Ipv4Addr {
- *self
- }
-}
-
impl fmt::Display for Ipv4Addr {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let octets = self.octets();
@@ -550,7 +538,7 @@ impl fmt::Display for Ipv6Addr {
/// does not require that `sun_len` include the terminating null even for normal
/// sockets. Note that the actual sockaddr length is greater by
/// `offset_of!(libc::sockaddr_un, sun_path)`
-#[derive(Copy)]
+#[derive(Clone, Copy)]
pub struct UnixAddr(pub libc::sockaddr_un, pub usize);
impl UnixAddr {
@@ -657,12 +645,6 @@ impl hash::Hash for UnixAddr {
}
}
-impl Clone for UnixAddr {
- fn clone(&self) -> UnixAddr {
- *self
- }
-}
-
impl fmt::Display for UnixAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.1 == 0 {
@@ -683,7 +665,7 @@ impl fmt::Display for UnixAddr {
*/
/// Represents a socket address
-#[derive(Copy)]
+#[derive(Clone, Copy)]
pub enum SockAddr {
Inet(InetAddr),
Unix(UnixAddr),
@@ -750,8 +732,7 @@ impl SockAddr {
SysControlAddr(*(addr as *const sys_control::sockaddr_ctl)))),
// Other address families are currently not supported and simply yield a None
// entry instead of a proper conversion to a `SockAddr`.
- Some(_) => None,
- None => None,
+ Some(_) | None => None,
}
}
}
@@ -803,12 +784,6 @@ impl hash::Hash for SockAddr {
}
}
-impl Clone for SockAddr {
- fn clone(&self) -> SockAddr {
- *self
- }
-}
-
impl fmt::Display for SockAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 8aa65369..0c7fbb97 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -226,7 +226,7 @@ impl IpMembershipRequest {
pub fn new(group: Ipv4Addr, interface: Option<Ipv4Addr>) -> Self {
IpMembershipRequest(libc::ip_mreq {
imr_multiaddr: group.0,
- imr_interface: interface.unwrap_or(Ipv4Addr::any()).0,
+ imr_interface: interface.unwrap_or_else(Ipv4Addr::any).0,
})
}
}
@@ -407,7 +407,7 @@ impl<'a> Iterator for CmsgIterator<'a> {
},
(_, _) => unsafe {
Some(ControlMessage::Unknown(UnknownCmsg(
- &cmsg,
+ cmsg,
slice::from_raw_parts(
cmsg_data.as_ptr() as *const _,
len))))
@@ -612,7 +612,7 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<'
let (name, namelen) = match addr {
Some(addr) => { let (x, y) = unsafe { addr.as_ffi_pair() }; (x as *const _, y) }
- None => (0 as *const _, 0),
+ None => (ptr::null(), 0),
};
let cmsg_ptr = if capacity > 0 {
@@ -644,7 +644,7 @@ pub fn recvmsg<'a, T>(fd: RawFd, iov: &[IoVec<&mut [u8]>], cmsg_buffer: Option<&
let mut address: sockaddr_storage = unsafe { mem::uninitialized() };
let (msg_control, msg_controllen) = match cmsg_buffer {
Some(cmsg_buffer) => (cmsg_buffer as *mut _, mem::size_of_val(cmsg_buffer)),
- None => (0 as *mut _, 0),
+ None => (ptr::null_mut(), 0),
};
let mut mhdr = unsafe {
let mut mhdr: msghdr = mem::uninitialized();
@@ -689,7 +689,7 @@ pub fn socket<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: SockType
let feat_atomic = features::socket_atomic_cloexec();
if feat_atomic {
- ty = ty | flags.bits();
+ ty |= flags.bits();
}
// TODO: Check the kernel version
@@ -732,7 +732,7 @@ pub fn socketpair<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: Sock
let feat_atomic = features::socket_atomic_cloexec();
if feat_atomic {
- ty = ty | flags.bits();
+ ty |= flags.bits();
}
let mut fds = [-1, -1];
let res = unsafe {
@@ -1015,9 +1015,9 @@ pub fn getsockname(fd: RawFd) -> Result<SockAddr> {
}
}
-/// Return the appropriate SockAddr type from a `sockaddr_storage` of a certain
+/// Return the appropriate `SockAddr` type from a `sockaddr_storage` of a certain
/// size. In C this would usually be done by casting. The `len` argument
-/// should be the number of bytes in the sockaddr_storage that are actually
+/// should be the number of bytes in the `sockaddr_storage` that are actually
/// allocated and valid. It must be at least as large as all the useful parts
/// of the structure. Note that in the case of a `sockaddr_un`, `len` need not
/// include the terminating null.
@@ -1037,7 +1037,7 @@ pub unsafe fn sockaddr_storage_to_addr(
}
libc::AF_INET6 => {
assert!(len as usize == mem::size_of::<sockaddr_in6>());
- Ok(SockAddr::Inet(InetAddr::V6((*(addr as *const _ as *const sockaddr_in6)))))
+ Ok(SockAddr::Inet(InetAddr::V6(*(addr as *const _ as *const sockaddr_in6))))
}
libc::AF_UNIX => {
let sun = *(addr as *const _ as *const sockaddr_un);
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index 9c0129f5..1f0d728a 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -53,22 +53,22 @@ pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t)
#[cfg(target_os = "linux")]
pub fn major(dev: dev_t) -> u64 {
- ((dev >> 32) & 0xfffff000) |
- ((dev >> 8) & 0x00000fff)
+ ((dev >> 32) & 0xffff_f000) |
+ ((dev >> 8) & 0x0000_0fff)
}
#[cfg(target_os = "linux")]
pub fn minor(dev: dev_t) -> u64 {
- ((dev >> 12) & 0xffffff00) |
- ((dev ) & 0x000000ff)
+ ((dev >> 12) & 0xffff_ff00) |
+ ((dev ) & 0x0000_00ff)
}
#[cfg(target_os = "linux")]
pub fn makedev(major: u64, minor: u64) -> dev_t {
- ((major & 0xfffff000) << 32) |
- ((major & 0x00000fff) << 8) |
- ((minor & 0xffffff00) << 12) |
- ((minor & 0x000000ff) )
+ ((major & 0xffff_f000) << 32) |
+ ((major & 0x0000_0fff) << 8) |
+ ((minor & 0xffff_ff00) << 12) |
+ (minor & 0x0000_00ff)
}
pub fn umask(mode: Mode) -> Mode {
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index e27cee40..b768caa8 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -349,7 +349,7 @@ impl From<libc::speed_t> for BaudRate {
B3500000 => BaudRate::B3500000,
#[cfg(any(target_os = "android", target_os = "linux"))]
B4000000 => BaudRate::B4000000,
- b @ _ => unreachable!("Invalid baud constant: {}", b),
+ b => unreachable!("Invalid baud constant: {}", b),
}
}
}
diff --git a/src/sys/uio.rs b/src/sys/uio.rs
index c785225b..7447f3ff 100644
--- a/src/sys/uio.rs
+++ b/src/sys/uio.rs
@@ -62,7 +62,7 @@ pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
///
/// This is the same underlying C structure as [`IoVec`](struct.IoVec.html),
/// except that it refers to memory in some other process, and is
-/// therefore not represented in Rust by an actual slice as IoVec is. It
+/// therefore not represented in Rust by an actual slice as `IoVec` is. It
/// is used with [`process_vm_readv`](fn.process_vm_readv.html)
/// and [`process_vm_writev`](fn.process_vm_writev.html).
#[cfg(target_os = "linux")]
@@ -81,7 +81,7 @@ pub struct RemoteIoVec {
/// and `remote_iov` is a list of [`RemoteIoVec`]s identifying where the
/// data should be written in the target process. On success, returns the
/// number of bytes written, which will always be a whole
-/// number of remote_iov chunks.
+/// number of `remote_iov` chunks.
///
/// This requires the same permissions as debugging the process using
/// [ptrace]: you must either be a privileged process (with
@@ -112,17 +112,17 @@ pub fn process_vm_writev(pid: ::unistd::Pid, local_iov: &[IoVec<&[u8]>], remote_
/// data into, and `remote_iov` is a list of [`RemoteIoVec`]s identifying
/// where the source data is in the target process. On success,
/// returns the number of bytes written, which will always be a whole
-/// number of remote_iov chunks.
+/// number of `remote_iov` chunks.
///
/// This requires the same permissions as debugging the process using
-/// [ptrace]: you must either be a privileged process (with
+/// [`ptrace`]: you must either be a privileged process (with
/// `CAP_SYS_PTRACE`), or you must be running as the same user as the
/// target process and the OS must have unprivileged debugging enabled.
///
/// This function is only available on Linux.
///
/// [`process_vm_readv`(2)]: http://man7.org/linux/man-pages/man2/process_vm_readv.2.html
-/// [ptrace]: ../ptrace/index.html
+/// [`ptrace`]: ../ptrace/index.html
/// [`IoVec`]: struct.IoVec.html
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
#[cfg(any(target_os = "linux"))]
@@ -141,7 +141,7 @@ pub struct IoVec<T>(libc::iovec, PhantomData<T>);
impl<T> IoVec<T> {
#[inline]
- pub fn as_slice<'a>(&'a self) -> &'a [u8] {
+ pub fn as_slice(&self) -> &[u8] {
use std::slice;
unsafe {
diff --git a/src/sys/utsname.rs b/src/sys/utsname.rs
index 885fa7d8..afec3e20 100644
--- a/src/sys/utsname.rs
+++ b/src/sys/utsname.rs
@@ -4,30 +4,27 @@ use std::ffi::CStr;
use std::str::from_utf8_unchecked;
#[repr(C)]
-#[derive(Copy)]
+#[derive(Clone, Copy)]
pub struct UtsName(libc::utsname);
-// workaround for `derive(Clone)` not working for fixed-length arrays
-impl Clone for UtsName { fn clone(&self) -> UtsName { *self } }
-
impl UtsName {
- pub fn sysname<'a>(&'a self) -> &'a str {
+ pub fn sysname(&self) -> &str {
to_str(&(&self.0.sysname as *const c_char ) as *const *const c_char)
}
- pub fn nodename<'a>(&'a self) -> &'a str {
+ pub fn nodename(&self) -> &str {
to_str(&(&self.0.nodename as *const c_char ) as *const *const c_char)
}
- pub fn release<'a>(&'a self) -> &'a str {
+ pub fn release(&self) -> &str {
to_str(&(&self.0.release as *const c_char ) as *const *const c_char)
}
- pub fn version<'a>(&'a self) -> &'a str {
+ pub fn version(&self) -> &str {
to_str(&(&self.0.version as *const c_char ) as *const *const c_char)
}
- pub fn machine<'a>(&'a self) -> &'a str {
+ pub fn machine(&self) -> &str {
to_str(&(&self.0.machine as *const c_char ) as *const *const c_char)
}
}
diff --git a/src/sys/wait.rs b/src/sys/wait.rs
index ba5dc27a..53c6a5f2 100644
--- a/src/sys/wait.rs
+++ b/src/sys/wait.rs
@@ -104,16 +104,11 @@ impl WaitStatus {
pub fn pid(&self) -> Option<Pid> {
use self::WaitStatus::*;
match *self {
- Exited(p, _) => Some(p),
- Signaled(p, _, _) => Some(p),
- Stopped(p, _) => Some(p),
- Continued(p) => Some(p),
+ Exited(p, _) | Signaled(p, _, _) |
+ Stopped(p, _) | Continued(p) => Some(p),
StillAlive => None,
-
- #[cfg(any(target_os = "linux", target_os = "android"))]
- PtraceEvent(p, _, _) => Some(p),
- #[cfg(any(target_os = "linux", target_os = "android"))]
- PtraceSyscall(p) => Some(p),
+ #[cfg(any(target_os = "android", target_os = "linux"))]
+ PtraceEvent(p, _, _) | PtraceSyscall(p) => Some(p),
}
}
}
diff --git a/src/unistd.rs b/src/unistd.rs
index 7a1c56c7..56390d90 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -480,7 +480,7 @@ pub fn mkfifo<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
Errno::result(res).map(drop)
}
-/// Returns the current directory as a PathBuf
+/// Returns the current directory as a `PathBuf`
///
/// Err is returned if the current user doesn't have the permission to read or search a component
/// of the current path.
@@ -729,7 +729,7 @@ pub fn sethostname<S: AsRef<OsStr>>(name: S) -> Result<()> {
}
/// Get the host name and store it in the provided buffer, returning a pointer
-/// the CStr in that buffer on success (see
+/// the `CStr` in that buffer on success (see
/// [gethostname(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/gethostname.html)).
///
/// This function call attempts to get the host name for the running system and
@@ -748,7 +748,7 @@ pub fn sethostname<S: AsRef<OsStr>>(name: S) -> Result<()> {
/// let hostname = hostname_cstr.to_str().expect("Hostname wasn't valid UTF-8");
/// println!("Hostname: {}", hostname);
/// ```
-pub fn gethostname<'a>(buffer: &'a mut [u8]) -> Result<&'a CStr> {
+pub fn gethostname(buffer: &mut [u8]) -> Result<&CStr> {
let ptr = buffer.as_mut_ptr() as *mut c_char;
let len = buffer.len() as size_t;
@@ -1337,7 +1337,7 @@ pub fn sleep(seconds: libc::c_uint) -> c_uint {
/// Creates a regular file which persists even after process termination
///
-/// * `template`: a path whose 6 rightmost characters must be X, e.g. /tmp/tmpfile_XXXXXX
+/// * `template`: a path whose 6 rightmost characters must be X, e.g. `/tmp/tmpfile_XXXXXX`
/// * returns: tuple of file descriptor and filename
///
/// Err is returned either if no temporary filename could be created or the template doesn't
diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs
index 79a6b6c4..1f807585 100644
--- a/test/sys/test_aio.rs
+++ b/test/sys/test_aio.rs
@@ -49,12 +49,12 @@ fn test_accessors() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_cancel() {
- let wbuf: &'static [u8] = b"CDEF";
+ let wbuf: &[u8] = b"CDEF";
let f = tempfile().unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
0, //offset
- &wbuf,
+ wbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -74,12 +74,12 @@ fn test_cancel() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_aio_cancel_all() {
- let wbuf: &'static [u8] = b"CDEF";
+ let wbuf: &[u8] = b"CDEF";
let f = tempfile().unwrap();
let mut aiocb = AioCb::from_slice(f.as_raw_fd(),
0, //offset
- &wbuf,
+ wbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -98,9 +98,9 @@ fn test_aio_cancel_all() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_fsync() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_fd( f.as_raw_fd(),
0, //priority
SigevNotify::SigevNone);
@@ -119,11 +119,11 @@ fn test_fsync() {
fn test_fsync_error() {
use std::mem;
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
// Create an invalid AioFsyncMode
let mode = unsafe { mem::transmute(666) };
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_fd( f.as_raw_fd(),
0, //priority
SigevNotify::SigevNone);
@@ -134,23 +134,23 @@ fn test_fsync_error() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_aio_suspend() {
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let timeout = TimeSpec::seconds(10);
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &mut WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -176,15 +176,15 @@ fn test_aio_suspend() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_read() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
- const EXPECT: &'static [u8] = b"cdef";
+ const EXPECT: &[u8] = b"cdef";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut aiocb = AioCb::from_boxed_slice( f.as_raw_fd(),
2, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -205,13 +205,13 @@ fn test_read() {
#[test]
#[cfg(any(target_os = "freebsd", target_os = "macos"))]
fn test_read_error() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_boxed_slice( f.as_raw_fd(),
-1, //an invalid offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -222,11 +222,11 @@ fn test_read_error() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_read_into_mut_slice() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let mut rbuf = vec![0; 4];
- const EXPECT: &'static [u8] = b"cdef";
+ const EXPECT: &[u8] = b"cdef";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut aiocb = AioCb::from_mut_slice( f.as_raw_fd(),
2, //offset
@@ -250,11 +250,11 @@ fn test_read_into_mut_slice() {
#[should_panic(expected = "Can't read into an immutable buffer")]
#[cfg_attr(target_env = "musl", ignore)]
fn test_read_immutable_buffer() {
- let rbuf: &'static [u8] = b"CDEF";
+ let rbuf: &[u8] = b"CDEF";
let f = tempfile().unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &rbuf,
+ rbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -267,13 +267,13 @@ fn test_read_immutable_buffer() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_write() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let wbuf = "CDEF".to_string().into_bytes();
let mut rbuf = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
&wbuf,
@@ -330,16 +330,16 @@ fn test_write_sigev_signal() {
SIGNALED.store(false, Ordering::Relaxed);
unsafe { sigaction(Signal::SIGUSR2, &sa) }.unwrap();
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let mut rbuf = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevSignal {
signal: Signal::SIGUSR2,
@@ -347,7 +347,7 @@ fn test_write_sigev_signal() {
},
LioOpcode::LIO_NOP);
aiocb.write().unwrap();
- while SIGNALED.load(Ordering::Relaxed) == false {
+ while !SIGNALED.load(Ordering::Relaxed) {
thread::sleep(time::Duration::from_millis(10));
}
@@ -364,26 +364,26 @@ fn test_write_sigev_signal() {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_lio_listio_wait() {
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut rbuf2 = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -407,26 +407,26 @@ fn test_lio_listio_wait() {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_lio_listio_nowait() {
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut rbuf2 = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -455,11 +455,11 @@ fn test_lio_listio_nowait() {
fn test_lio_listio_signal() {
#[allow(unused_variables)]
let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut rbuf2 = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
let sa = SigAction::new(SigHandler::Handler(sigfunc),
SaFlags::SA_RESETHAND,
@@ -467,19 +467,19 @@ fn test_lio_listio_signal() {
let sigev_notify = SigevNotify::SigevSignal { signal: Signal::SIGUSR2,
si_value: 0 };
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -487,7 +487,7 @@ fn test_lio_listio_signal() {
unsafe { sigaction(Signal::SIGUSR2, &sa) }.unwrap();
let err = lio_listio(LioMode::LIO_NOWAIT, &[&mut wcb, &mut rcb], sigev_notify);
err.expect("lio_listio failed");
- while SIGNALED.load(Ordering::Relaxed) == false {
+ while !SIGNALED.load(Ordering::Relaxed) {
thread::sleep(time::Duration::from_millis(10));
}
@@ -509,13 +509,13 @@ fn test_lio_listio_signal() {
#[should_panic(expected = "Can't read into an immutable buffer")]
#[cfg_attr(target_env = "musl", ignore)]
fn test_lio_listio_read_immutable() {
- let rbuf: &'static [u8] = b"abcd";
+ let rbuf: &[u8] = b"abcd";
let f = tempfile().unwrap();
let mut rcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &rbuf,
+ rbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
diff --git a/test/sys/test_aio_drop.rs b/test/sys/test_aio_drop.rs
index ef0f5041..1f4a3e79 100644
--- a/test/sys/test_aio_drop.rs
+++ b/test/sys/test_aio_drop.rs
@@ -13,13 +13,13 @@ use tempfile::tempfile;
#[should_panic(expected = "Dropped an in-progress AioCb")]
#[cfg(not(target_env = "musl"))]
fn test_drop() {
- const WBUF: &'static [u8] = b"CDEF";
+ const WBUF: &[u8] = b"CDEF";
let f = tempfile().unwrap();
f.set_len(6).unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs
index 1ed4a4b4..9a7a4819 100644
--- a/test/sys/test_ioctl.rs
+++ b/test/sys/test_ioctl.rs
@@ -87,22 +87,22 @@ mod linux {
#[test]
fn test_op_none() {
if cfg!(any(target_arch = "mips", target_arch = "mips64", target_arch="powerpc", target_arch="powerpc64")){
- assert_eq!(io!(b'q', 10), 0x2000710A);
- assert_eq!(io!(b'a', 255), 0x200061FF);
+ assert_eq!(io!(b'q', 10), 0x2000_710A);
+ assert_eq!(io!(b'a', 255), 0x2000_61FF);
} else {
- assert_eq!(io!(b'q', 10), 0x0000710A);
- assert_eq!(io!(b'a', 255), 0x000061FF);
+ assert_eq!(io!(b'q', 10), 0x0000_710A);
+ assert_eq!(io!(b'a', 255), 0x0000_61FF);
}
}
#[test]
fn test_op_write() {
if cfg!(any(target_arch = "mips", target_arch = "mips64", target_arch="powerpc", target_arch="powerpc64")){
- assert_eq!(iow!(b'z', 10, 1), 0x80017A0A);
- assert_eq!(iow!(b'z', 10, 512), 0x82007A0A);
+ assert_eq!(iow!(b'z', 10, 1), 0x8001_7A0A);
+ assert_eq!(iow!(b'z', 10, 512), 0x8200_7A0A);
} else {
- assert_eq!(iow!(b'z', 10, 1), 0x40017A0A);
- assert_eq!(iow!(b'z', 10, 512), 0x42007A0A);
+ assert_eq!(iow!(b'z', 10, 1), 0x4001_7A0A);
+ assert_eq!(iow!(b'z', 10, 512), 0x4200_7A0A);
}
}
@@ -110,9 +110,9 @@ mod linux {
#[test]
fn test_op_write_64() {
if cfg!(any(target_arch = "mips64", target_arch="powerpc64")){
- assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
+ assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x8000_7A0A);
} else {
- assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
+ assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x4000_7A0A);
}
}
@@ -120,11 +120,11 @@ mod linux {
#[test]
fn test_op_read() {
if cfg!(any(target_arch = "mips", target_arch = "mips64", target_arch="powerpc", target_arch="powerpc64")){
- assert_eq!(ior!(b'z', 10, 1), 0x40017A0A);
- assert_eq!(ior!(b'z', 10, 512), 0x42007A0A);
+ assert_eq!(ior!(b'z', 10, 1), 0x4001_7A0A);
+ assert_eq!(ior!(b'z', 10, 512), 0x4200_7A0A);
} else {
- assert_eq!(ior!(b'z', 10, 1), 0x80017A0A);
- assert_eq!(ior!(b'z', 10, 512), 0x82007A0A);
+ assert_eq!(ior!(b'z', 10, 1), 0x8001_7A0A);
+ assert_eq!(ior!(b'z', 10, 512), 0x8200_7A0A);
}
}
@@ -132,22 +132,22 @@ mod linux {
#[test]
fn test_op_read_64() {
if cfg!(any(target_arch = "mips64", target_arch="powerpc64")){
- assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
+ assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x4000_7A0A);
} else {
- assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
+ assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x8000_7A0A);
}
}
#[test]
fn test_op_read_write() {
- assert_eq!(iorw!(b'z', 10, 1), 0xC0017A0A);
- assert_eq!(iorw!(b'z', 10, 512), 0xC2007A0A);
+ assert_eq!(iorw!(b'z', 10, 1), 0xC001_7A0A);
+ assert_eq!(iorw!(b'z', 10, 512), 0xC200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
- assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC0007A0A);
+ assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC000_7A0A);
}
}
@@ -160,44 +160,44 @@ mod linux {
mod bsd {
#[test]
fn test_op_none() {
- assert_eq!(io!(b'q', 10), 0x2000710A);
- assert_eq!(io!(b'a', 255), 0x200061FF);
+ assert_eq!(io!(b'q', 10), 0x2000_710A);
+ assert_eq!(io!(b'a', 255), 0x2000_61FF);
}
#[test]
fn test_op_write() {
- assert_eq!(iow!(b'z', 10, 1), 0x80017A0A);
- assert_eq!(iow!(b'z', 10, 512), 0x82007A0A);
+ assert_eq!(iow!(b'z', 10, 1), 0x8001_7A0A);
+ assert_eq!(iow!(b'z', 10, 512), 0x8200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_write_64() {
- assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
+ assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x8000_7A0A);
}
#[test]
fn test_op_read() {
- assert_eq!(ior!(b'z', 10, 1), 0x40017A0A);
- assert_eq!(ior!(b'z', 10, 512), 0x42007A0A);
+ assert_eq!(ior!(b'z', 10, 1), 0x4001_7A0A);
+ assert_eq!(ior!(b'z', 10, 512), 0x4200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_64() {
- assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
+ assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x4000_7A0A);
}
#[test]
fn test_op_read_write() {
- assert_eq!(iorw!(b'z', 10, 1), 0xC0017A0A);
- assert_eq!(iorw!(b'z', 10, 512), 0xC2007A0A);
+ assert_eq!(iorw!(b'z', 10, 1), 0xC001_7A0A);
+ assert_eq!(iorw!(b'z', 10, 512), 0xC200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
- assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC0007A0A);
+ assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC000_7A0A);
}
}
@@ -269,10 +269,10 @@ mod linux_ioctls {
// From linux/videodev2.h
ioctl!(write_ptr s_audio with b'V', 34; v4l2_audio);
#[test]
- fn test_ioctl_read() {
+ fn test_ioctl_write_ptr() {
let file = tempfile().unwrap();
- let data: v4l2_audio = unsafe { mem::uninitialized() };
- let res = unsafe { g_audio(file.as_raw_fd(), &data) };
+ let data: v4l2_audio = unsafe { mem::zeroed() };
+ let res = unsafe { s_audio(file.as_raw_fd(), &data) };
assert!(res == Err(Sys(ENOTTY)) || res == Err(Sys(ENOSYS)));
}
@@ -288,9 +288,9 @@ mod linux_ioctls {
}
// From linux/videodev2.h
- ioctl!(write_ptr g_audio with b'V', 33; v4l2_audio);
+ ioctl!(read g_audio with b'V', 33; v4l2_audio);
#[test]
- fn test_ioctl_write_ptr() {
+ fn test_ioctl_read() {
let file = tempfile().unwrap();
let mut data: v4l2_audio = unsafe { mem::uninitialized() };
let res = unsafe { g_audio(file.as_raw_fd(), &mut data) };
@@ -328,8 +328,8 @@ mod linux_ioctls {
#[test]
fn test_ioctl_write_buf() {
let file = tempfile().unwrap();
- let mut data: [spi_ioc_transfer; 4] = unsafe { mem::uninitialized() };
- let res = unsafe { spi_ioc_message(file.as_raw_fd(), &mut data[..]) };
+ let data: [spi_ioc_transfer; 4] = unsafe { mem::zeroed() };
+ let res = unsafe { spi_ioc_message(file.as_raw_fd(), &data[..]) };
assert!(res == Err(Sys(ENOTTY)) || res == Err(Sys(ENOSYS)));
}
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs
index d3e579f3..debc4517 100644
--- a/test/sys/test_ptrace.rs
+++ b/test/sys/test_ptrace.rs
@@ -30,9 +30,8 @@ fn test_ptrace_getevent() {
// Just make sure ptrace_getsiginfo can be called at all, for now.
#[test]
fn test_ptrace_getsiginfo() {
- match ptrace::getsiginfo(getpid()) {
- Err(Error::UnsupportedOperation) => panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!"),
- _ => (),
+ if let Err(Error::UnsupportedOperation) = ptrace::getsiginfo(getpid()) {
+ panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!");
}
}
@@ -40,9 +39,8 @@ fn test_ptrace_getsiginfo() {
#[test]
fn test_ptrace_setsiginfo() {
let siginfo = unsafe { mem::uninitialized() };
- match ptrace::setsiginfo(getpid(), &siginfo) {
- Err(Error::UnsupportedOperation) => panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!"),
- _ => (),
+ if let Err(Error::UnsupportedOperation) = ptrace::setsiginfo(getpid(), &siginfo) {
+ panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!");
}
}
@@ -66,8 +64,8 @@ fn test_ptrace_cont() {
return;
}
- match fork() {
- Ok(Child) => {
+ match fork().expect("Error: Fork Failed") {
+ Child => {
ptrace::traceme().unwrap();
// As recommended by ptrace(2), raise SIGTRAP to pause the child
// until the parent is ready to continue
@@ -76,7 +74,7 @@ fn test_ptrace_cont() {
}
},
- Ok(Parent { child }) => {
+ Parent { child } => {
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP)));
ptrace::cont(child, None).unwrap();
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP)));
@@ -86,6 +84,5 @@ fn test_ptrace_cont() {
_ => panic!("The process should have been killed"),
}
},
- Err(_) => panic!("Error: Fork Failed")
}
}
diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs
index 4084a0da..ab99ab19 100644
--- a/test/sys/test_signal.rs
+++ b/test/sys/test_signal.rs
@@ -3,5 +3,5 @@ use nix::sys::signal::*;
#[test]
fn test_kill_none() {
- kill(getpid(), None).ok().expect("Should be able to send signal to myself.");
+ kill(getpid(), None).expect("Should be able to send signal to myself.");
}
diff --git a/test/sys/test_signalfd.rs b/test/sys/test_signalfd.rs
index 6d65e6a0..a2f8fd8f 100644
--- a/test/sys/test_signalfd.rs
+++ b/test/sys/test_signalfd.rs
@@ -17,7 +17,7 @@ fn test_signalfd() {
// Send a SIGUSR1 signal to the current process. Note that this uses `raise` instead of `kill`
// because `kill` with `getpid` isn't correct during multi-threaded execution like during a
// cargo test session. Instead use `raise` which does the correct thing by default.
- raise(signal::SIGUSR1).ok().expect("Error: raise(SIGUSR1) failed");
+ raise(signal::SIGUSR1).expect("Error: raise(SIGUSR1) failed");
// And now catch that same signal.
let res = fd.read_signal().unwrap().unwrap();
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index d29b2ecb..a997fbca 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -13,7 +13,7 @@ pub fn test_inetv4_addr_to_sock_addr() {
match addr {
InetAddr::V4(addr) => {
- let ip: u32 = 0x7f000001;
+ let ip: u32 = 0x7f00_0001;
let port: u16 = 3000;
assert_eq!(addr.sin_addr.s_addr, ip.to_be());
diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs
index 81db8248..a38657c1 100644
--- a/test/sys/test_sockopt.rs
+++ b/test/sys/test_sockopt.rs
@@ -5,7 +5,7 @@ use nix::sys::socket::{socket, sockopt, getsockopt, setsockopt, AddressFamily, S
fn test_so_buf() {
let fd = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), SockProtocol::Udp)
.unwrap();
- let bufsize: usize = thread_rng().gen_range(4096, 131072);
+ let bufsize: usize = thread_rng().gen_range(4096, 131_072);
setsockopt(fd, sockopt::SndBuf, &bufsize).unwrap();
let actual = getsockopt(fd, sockopt::SndBuf).unwrap();
assert!(actual >= bufsize);
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index a3a948b3..903a5353 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -7,7 +7,7 @@ use nix::pty::openpty;
use nix::sys::termios::{self, LocalFlags, OutputFlags, Termios, tcgetattr};
use nix::unistd::{read, write, close};
-/// Helper function analogous to std::io::Write::write_all, but for `RawFd`s
+/// Helper function analogous to `std::io::Write::write_all`, but for `RawFd`s
fn write_all(f: RawFd, buf: &[u8]) {
let mut len = 0;
while len < buf.len() {
diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs
index a2b68d07..c6331f1d 100644
--- a/test/sys/test_uio.rs
+++ b/test/sys/test_uio.rs
@@ -14,7 +14,7 @@ fn test_writev() {
for _ in 0..16 {
let s: String = thread_rng().gen_ascii_chars().take(128).collect();
let b = s.as_bytes();
- to_write.extend(b.iter().map(|x| x.clone()));
+ to_write.extend(b.iter().cloned());
}
// Allocate and fill iovecs
let mut iovecs = Vec::new();
@@ -66,7 +66,7 @@ fn test_readv() {
allocated += vec_len;
}
let mut iovecs = Vec::with_capacity(storage.len());
- for v in storage.iter_mut() {
+ for v in &mut storage {
iovecs.push(IoVec::from_mut_slice(&mut v[..]));
}
let pipe_res = pipe();
@@ -83,8 +83,8 @@ fn test_readv() {
assert_eq!(to_write.len(), read);
// Cccumulate data from iovecs
let mut read_buf = Vec::with_capacity(to_write.len());
- for iovec in iovecs.iter() {
- read_buf.extend(iovec.as_slice().iter().map(|x| x.clone()));
+ for iovec in &iovecs {
+ read_buf.extend(iovec.as_slice().iter().cloned());
}
// Check whether iovecs contain all written data
assert_eq!(read_buf.len(), to_write.len());
@@ -208,11 +208,11 @@ fn test_process_vm_readv() {
let mut vector = vec![1u8, 2, 3, 4, 5];
let (r, w) = pipe().unwrap();
- match fork() {
- Ok(Parent { child }) => {
+ match fork().expect("Error: Fork Failed") {
+ Parent { child } => {
close(w).unwrap();
// wait for child
- read(r, &mut vec![0u8]).unwrap();
+ read(r, &mut [0u8]).unwrap();
close(r).unwrap();
let ptr = vector.as_ptr() as usize;
@@ -229,15 +229,14 @@ fn test_process_vm_readv() {
assert_eq!(Ok(5), ret);
assert_eq!(20u8, buf.iter().sum());
},
- Ok(Child) => {
+ Child => {
let _ = close(r);
- for i in vector.iter_mut() {
+ for i in &mut vector {
*i += 1;
}
let _ = write(w, b"\0");
let _ = close(w);
loop { let _ = pause(); }
},
- Err(_) => panic!("fork failed")
}
}
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 02f32734..9992607c 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -11,14 +11,12 @@ fn test_wait_signal() {
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: The child only calls `pause` and/or `_exit`, which are async-signal-safe.
- match fork() {
- Ok(Child) => pause().unwrap_or_else(|_| unsafe { _exit(123) }),
- Ok(Parent { child }) => {
- kill(child, Some(SIGKILL)).ok().expect("Error: Kill Failed");
+ match fork().expect("Error: Fork Failed") {
+ Child => pause().unwrap_or_else(|_| unsafe { _exit(123) }),
+ Parent { child } => {
+ kill(child, Some(SIGKILL)).expect("Error: Kill Failed");
assert_eq!(waitpid(child, None), Ok(WaitStatus::Signaled(child, SIGKILL, false)));
},
- // panic, fork should never fail unless there is a serious problem with the OS
- Err(_) => panic!("Error: Fork Failed")
}
}
@@ -28,13 +26,11 @@ fn test_wait_exit() {
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: Child only calls `_exit`, which is async-signal-safe.
- match fork() {
- Ok(Child) => unsafe { _exit(12); },
- Ok(Parent { child }) => {
+ match fork().expect("Error: Fork Failed") {
+ Child => unsafe { _exit(12); },
+ Parent { child } => {
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 12)));
},
- // panic, fork should never fail unless there is a serious problem with the OS
- Err(_) => panic!("Error: Fork Failed")
}
}
@@ -100,10 +96,9 @@ mod ptrace {
#[allow(unused_variables)]
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
- match fork() {
- Ok(Child) => ptrace_child(),
- Ok(Parent { child }) => ptrace_parent(child),
- Err(_) => panic!("Error: Fork Failed")
+ match fork().expect("Error: Fork Failed") {
+ Child => ptrace_child(),
+ Parent { child } => ptrace_parent(child),
}
}
}
diff --git a/test/test.rs b/test/test.rs
index 42065694..14cbd7bc 100644
--- a/test/test.rs
+++ b/test/test.rs
@@ -26,7 +26,7 @@ use std::os::unix::io::RawFd;
use std::sync::Mutex;
use nix::unistd::read;
-/// Helper function analogous to std::io::Read::read_exact, but for `RawFD`s
+/// Helper function analogous to `std::io::Read::read_exact`, but for `RawFD`s
fn read_exact(f: RawFd, buf: &mut [u8]) {
let mut len = 0;
while len < buf.len() {
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index 795b6c85..57b35837 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -8,9 +8,9 @@ use std::os::unix::fs;
#[test]
fn test_openat() {
- const CONTENTS: &'static [u8] = b"abcd";
+ const CONTENTS: &[u8] = b"abcd";
let mut tmp = NamedTempFile::new().unwrap();
- tmp.write(CONTENTS).unwrap();
+ tmp.write_all(CONTENTS).unwrap();
let dirfd = open(tmp.path().parent().unwrap(),
OFlag::empty(),
@@ -62,9 +62,9 @@ mod linux_android {
#[test]
fn test_splice() {
- const CONTENTS: &'static [u8] = b"abcdef123456";
+ const CONTENTS: &[u8] = b"abcdef123456";
let mut tmp = tempfile().unwrap();
- tmp.write(CONTENTS).unwrap();
+ tmp.write_all(CONTENTS).unwrap();
let (rd, wr) = pipe().unwrap();
let mut offset: loff_t = 5;
diff --git a/test/test_mount.rs b/test/test_mount.rs
index e4cd6ba7..89416a43 100644
--- a/test/test_mount.rs
+++ b/test/test_mount.rs
@@ -213,15 +213,15 @@ exit 23";
/// Mimic normal test output (hackishly).
macro_rules! run_tests {
( $($test_fn:ident),* ) => {{
- print!("\n");
+ println!();
$(
print!("test test_mount::{} ... ", stringify!($test_fn));
$test_fn();
- print!("ok\n");
+ println!("ok");
)*
- print!("\n");
+ println!();
}}
}
diff --git a/test/test_mq.rs b/test/test_mq.rs
index bf32696c..0f46f24b 100644
--- a/test/test_mq.rs
+++ b/test/test_mq.rs
@@ -39,7 +39,7 @@ fn test_mq_send_and_receive() {
fn test_mq_getattr() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
- let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap();
+ let mq_name = &CString::new(b"/attr_test_get_attr".as_ref()).unwrap();
let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
let read_attr = mq_getattr(mqd);
assert!(read_attr.unwrap() == initial_attr);
@@ -52,7 +52,7 @@ fn test_mq_getattr() {
fn test_mq_setattr() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
- let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap();
+ let mq_name = &CString::new(b"/attr_test_get_attr".as_ref()).unwrap();
let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
let new_attr = MqAttr::new(0, 20, MSG_SIZE * 2, 100);
@@ -80,7 +80,7 @@ fn test_mq_setattr() {
fn test_mq_set_nonblocking() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
- let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap();
+ let mq_name = &CString::new(b"/attr_test_get_attr".as_ref()).unwrap();
let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
mq_set_nonblock(mqd).unwrap();
let new_attr = mq_getattr(mqd);
@@ -95,8 +95,8 @@ fn test_mq_set_nonblocking() {
fn test_mq_unlink() {
const MSG_SIZE: c_long = 32;
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
- let mq_name_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap();
- let mq_name_not_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap();
+ let mq_name_opened = &CString::new(b"/mq_unlink_test".as_ref()).unwrap();
+ let mq_name_not_opened = &CString::new(b"/mq_unlink_test".as_ref()).unwrap();
let mqd = mq_open(mq_name_opened, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap();
let res_unlink = mq_unlink(mq_name_opened);
diff --git a/test/test_net.rs b/test/test_net.rs
index 24bd411a..b8940e71 100644
--- a/test/test_net.rs
+++ b/test/test_net.rs
@@ -1,10 +1,10 @@
use nix::net::if_::*;
#[cfg(any(target_os = "android", target_os = "linux"))]
-const LOOPBACK: &'static [u8] = b"lo";
+const LOOPBACK: &[u8] = b"lo";
#[cfg(not(any(target_os = "android", target_os = "linux")))]
-const LOOPBACK: &'static [u8] = b"lo0";
+const LOOPBACK: &[u8] = b"lo0";
#[test]
fn test_if_nametoindex() {
diff --git a/test/test_pty.rs b/test/test_pty.rs
index 7104a9a5..0adcc99f 100644
--- a/test/test_pty.rs
+++ b/test/test_pty.rs
@@ -10,7 +10,7 @@ use nix::sys::termios::*;
use nix::unistd::{write, close};
/// Regression test for Issue #659
-/// This is the correct way to explicitly close a PtyMaster
+/// This is the correct way to explicitly close a `PtyMaster`
#[test]
fn test_explicit_close() {
let mut f = {
@@ -20,7 +20,7 @@ fn test_explicit_close() {
};
// This should work. But if there's been a double close, then it will
// return EBADF
- f.write(b"whatever").unwrap();
+ f.write_all(b"whatever").unwrap();
}
/// Test equivalence of `ptsname` and `ptsname_r`
diff --git a/test/test_ptymaster_drop.rs b/test/test_ptymaster_drop.rs
index bde8510c..9b59d664 100644
--- a/test/test_ptymaster_drop.rs
+++ b/test/test_ptymaster_drop.rs
@@ -6,7 +6,7 @@ use nix::unistd::close;
use std::os::unix::io::AsRawFd;
/// Regression test for Issue #659
-/// PtyMaster should panic rather than double close the file descriptor
+/// `PtyMaster` should panic rather than double close the file descriptor
/// This must run in its own test process because it deliberately creates a race
/// condition.
#[test]
diff --git a/test/test_sendfile.rs b/test/test_sendfile.rs
index 7db65b9a..7b51a1a6 100644
--- a/test/test_sendfile.rs
+++ b/test/test_sendfile.rs
@@ -10,9 +10,9 @@ use nix::sys::sendfile::sendfile;
#[test]
fn test_sendfile() {
- const CONTENTS: &'static [u8] = b"abcdef123456";
+ const CONTENTS: &[u8] = b"abcdef123456";
let mut tmp = tempfile().unwrap();
- tmp.write(CONTENTS).unwrap();
+ tmp.write_all(CONTENTS).unwrap();
let (rd, wr) = pipe().unwrap();
let mut offset: off_t = 5;
diff --git a/test/test_stat.rs b/test/test_stat.rs
index 900def89..a65778ea 100644
--- a/test/test_stat.rs
+++ b/test/test_stat.rs
@@ -21,44 +21,36 @@ fn valid_uid_gid(stat: FileStat) -> bool {
}
fn assert_stat_results(stat_result: Result<FileStat>) {
- match stat_result {
- Ok(stats) => {
- assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
- assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent
- assert!(stats.st_mode > 0); // must be positive integer
- assert!(stats.st_nlink == 1); // there links created, must be 1
- assert!(valid_uid_gid(stats)); // must be positive integers
- assert!(stats.st_size == 0); // size is 0 because we did not write anything to the file
- assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent
- assert!(stats.st_blocks <= 16); // Up to 16 blocks can be allocated for a blank file
- }
- Err(_) => panic!("stat call failed") // if stats system call fails, something is seriously wrong on that machine
- }
+ let stats = stat_result.expect("stat call failed");
+ assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
+ assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent
+ assert!(stats.st_mode > 0); // must be positive integer
+ assert!(stats.st_nlink == 1); // there links created, must be 1
+ assert!(valid_uid_gid(stats)); // must be positive integers
+ assert!(stats.st_size == 0); // size is 0 because we did not write anything to the file
+ assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent
+ assert!(stats.st_blocks <= 16); // Up to 16 blocks can be allocated for a blank file
}
fn assert_lstat_results(stat_result: Result<FileStat>) {
- match stat_result {
- Ok(stats) => {
- assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
- assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent
- assert!(stats.st_mode > 0); // must be positive integer
-
- // st_mode is c_uint (u32 on Android) while S_IFMT is mode_t
- // (u16 on Android), and that will be a compile error.
- // On other platforms they are the same (either both are u16 or u32).
- assert!((stats.st_mode as usize) & (S_IFMT as usize) == S_IFLNK as usize); // should be a link
- assert!(stats.st_nlink == 1); // there links created, must be 1
- assert!(valid_uid_gid(stats)); // must be positive integers
- assert!(stats.st_size > 0); // size is > 0 because it points to another file
- assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent
-
- // st_blocks depends on whether the machine's file system uses fast
- // or slow symlinks, so just make sure it's not negative
- // (Android's st_blocks is ulonglong which is always non-negative.)
- assert!(stats.st_blocks >= 0);
- }
- Err(_) => panic!("stat call failed") // if stats system call fails, something is seriously wrong on that machine
- }
+ let stats = stat_result.expect("stat call failed");
+ assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
+ assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent
+ assert!(stats.st_mode > 0); // must be positive integer
+
+ // st_mode is c_uint (u32 on Android) while S_IFMT is mode_t
+ // (u16 on Android), and that will be a compile error.
+ // On other platforms they are the same (either both are u16 or u32).
+ assert!((stats.st_mode as usize) & (S_IFMT as usize) == S_IFLNK as usize); // should be a link
+ assert!(stats.st_nlink == 1); // there links created, must be 1
+ assert!(valid_uid_gid(stats)); // must be positive integers
+ assert!(stats.st_size > 0); // size is > 0 because it points to another file
+ assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent
+
+ // st_blocks depends on whether the machine's file system uses fast
+ // or slow symlinks, so just make sure it's not negative
+ // (Android's st_blocks is ulonglong which is always non-negative.)
+ assert!(stats.st_blocks >= 0);
}
#[test]
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 93b54143..e15fec17 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -20,9 +20,9 @@ fn test_fork_and_waitpid() {
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: Child only calls `_exit`, which is signal-safe
- match fork() {
- Ok(Child) => unsafe { _exit(0) },
- Ok(Parent { child }) => {
+ match fork().expect("Error: Fork Failed") {
+ Child => unsafe { _exit(0) },
+ Parent { child } => {
// assert that child was created and pid > 0
let child_raw: ::libc::pid_t = child.into();
assert!(child_raw > 0);
@@ -39,8 +39,6 @@ fn test_fork_and_waitpid() {
}
},
- // panic, fork should never fail unless there is a serious problem with the OS
- Err(_) => panic!("Error: Fork Failed")
}
}
@@ -51,17 +49,14 @@ fn test_wait() {
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: Child only calls `_exit`, which is signal-safe
- let pid = fork();
- match pid {
- Ok(Child) => unsafe { _exit(0) },
- Ok(Parent { child }) => {
+ match fork().expect("Error: Fork Failed") {
+ Child => unsafe { _exit(0) },
+ Parent { child } => {
let wait_status = wait();
// just assert that (any) one child returns with WaitStatus::Exited
assert_eq!(wait_status, Ok(WaitStatus::Exited(child, 0)));
},
- // panic, fork should never fail unless there is a serious problem with the OS
- Err(_) => panic!("Error: Fork Failed")
}
}
@@ -319,7 +314,7 @@ fn test_getcwd() {
#[test]
fn test_lseek() {
- const CONTENTS: &'static [u8] = b"abcdef123456";
+ const CONTENTS: &[u8] = b"abcdef123456";
let mut tmp = tempfile().unwrap();
tmp.write_all(CONTENTS).unwrap();
let tmpfd = tmp.into_raw_fd();
@@ -337,9 +332,9 @@ fn test_lseek() {
#[cfg(any(target_os = "linux", target_os = "android"))]
#[test]
fn test_lseek64() {
- const CONTENTS: &'static [u8] = b"abcdef123456";
+ const CONTENTS: &[u8] = b"abcdef123456";
let mut tmp = tempfile().unwrap();
- tmp.write(CONTENTS).unwrap();
+ tmp.write_all(CONTENTS).unwrap();
let tmpfd = tmp.into_raw_fd();
lseek64(tmpfd, 5, Whence::SeekSet).unwrap();