From 149d6c1009e9c59b37076e5dba3e282c91b06ea1 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:18:14 -0800 Subject: Use write_all instead of write Several tests make the assumption that all data is written, which is not guaranteed with write(), so use write_all() instead. --- test/sys/test_aio.rs | 22 +++++++++++----------- test/test_fcntl.rs | 4 ++-- test/test_pty.rs | 2 +- test/test_sendfile.rs | 2 +- test/test_unistd.rs | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 79a6b6c4..7cfc313d 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -100,7 +100,7 @@ fn test_aio_cancel_all() { fn test_fsync() { const INITIAL: &'static [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); @@ -123,7 +123,7 @@ fn test_fsync_error() { // 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); @@ -139,7 +139,7 @@ fn test_aio_suspend() { 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 @@ -180,7 +180,7 @@ fn test_read() { let rbuf = Rc::new(vec![0; 4].into_boxed_slice()); const EXPECT: &'static [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 @@ -208,7 +208,7 @@ fn test_read_error() { const INITIAL: &'static [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(), @@ -226,7 +226,7 @@ fn test_read_into_mut_slice() { let mut rbuf = vec![0; 4]; const EXPECT: &'static [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 @@ -273,7 +273,7 @@ fn test_write() { const EXPECT: &'static [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, @@ -336,7 +336,7 @@ fn test_write_sigev_signal() { const EXPECT: &'static [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, @@ -371,7 +371,7 @@ fn test_lio_listio_wait() { const EXPECT: &'static [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(), @@ -414,7 +414,7 @@ fn test_lio_listio_nowait() { const EXPECT: &'static [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(), @@ -467,7 +467,7 @@ 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(), diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 795b6c85..6c232258 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -10,7 +10,7 @@ use std::os::unix::fs; fn test_openat() { const CONTENTS: &'static [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(), @@ -64,7 +64,7 @@ mod linux_android { fn test_splice() { const CONTENTS: &'static [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_pty.rs b/test/test_pty.rs index 7104a9a5..0060f60d 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -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_sendfile.rs b/test/test_sendfile.rs index 7db65b9a..689f5a60 100644 --- a/test/test_sendfile.rs +++ b/test/test_sendfile.rs @@ -12,7 +12,7 @@ use nix::sys::sendfile::sendfile; fn test_sendfile() { const CONTENTS: &'static [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_unistd.rs b/test/test_unistd.rs index 93b54143..e8f9b448 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -339,7 +339,7 @@ fn test_lseek() { fn test_lseek64() { const CONTENTS: &'static [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(); -- cgit v1.2.3 From 73ea706da54da4e19a49c78e1189777176f43810 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:23:56 -0800 Subject: Use byte strings instead of String.as_bytes() A little easier to read --- test/test_mq.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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); -- cgit v1.2.3 From 68859b9c1897c747263f5844cf87d9f4ac9e6f04 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:28:45 -0800 Subject: Add backticks to types in doccomments --- test/sys/test_termios.rs | 2 +- test/test.rs | 2 +- test/test_pty.rs | 2 +- test/test_ptymaster_drop.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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/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_pty.rs b/test/test_pty.rs index 0060f60d..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 = { 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] -- cgit v1.2.3 From 09a79fa1c5e67a07b07a160dca01474ec324ecf6 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:35:12 -0800 Subject: Remove useless vec![] --- test/sys/test_uio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index a2b68d07..76597790 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -212,7 +212,7 @@ fn test_process_vm_readv() { Ok(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; -- cgit v1.2.3 From ae8e4a4ba0a2c3300624b5ed560ac95ed6244005 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:41:37 -0800 Subject: Remove elided 'static lifetime As of Rust 1.17 'static lifetimes are implied when declaring consts. --- test/sys/test_aio.rs | 46 +++++++++++++++++++++++----------------------- test/sys/test_aio_drop.rs | 2 +- test/test_fcntl.rs | 4 ++-- test/test_net.rs | 4 ++-- test/test_sendfile.rs | 2 +- test/test_unistd.rs | 4 ++-- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 7cfc313d..4f151458 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -98,7 +98,7 @@ 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_all(INITIAL).unwrap(); let mut aiocb = AioCb::from_fd( f.as_raw_fd(), @@ -119,7 +119,7 @@ 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(); @@ -134,8 +134,8 @@ 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(); @@ -176,9 +176,9 @@ 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_all(INITIAL).unwrap(); { @@ -205,7 +205,7 @@ 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_all(INITIAL).unwrap(); @@ -222,9 +222,9 @@ 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_all(INITIAL).unwrap(); { @@ -267,10 +267,10 @@ 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_all(INITIAL).unwrap(); @@ -330,10 +330,10 @@ 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_all(INITIAL).unwrap(); @@ -364,11 +364,11 @@ 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_all(INITIAL).unwrap(); @@ -407,11 +407,11 @@ 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_all(INITIAL).unwrap(); @@ -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, diff --git a/test/sys/test_aio_drop.rs b/test/sys/test_aio_drop.rs index ef0f5041..9214957f 100644 --- a/test/sys/test_aio_drop.rs +++ b/test/sys/test_aio_drop.rs @@ -13,7 +13,7 @@ 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(); diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 6c232258..57b35837 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -8,7 +8,7 @@ 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_all(CONTENTS).unwrap(); @@ -62,7 +62,7 @@ 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_all(CONTENTS).unwrap(); 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_sendfile.rs b/test/test_sendfile.rs index 689f5a60..7b51a1a6 100644 --- a/test/test_sendfile.rs +++ b/test/test_sendfile.rs @@ -10,7 +10,7 @@ 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_all(CONTENTS).unwrap(); diff --git a/test/test_unistd.rs b/test/test_unistd.rs index e8f9b448..7c26210c 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -319,7 +319,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,7 +337,7 @@ 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_all(CONTENTS).unwrap(); let tmpfd = tmp.into_raw_fd(); -- cgit v1.2.3 From e831466614f7657d3ae20976d5f137f2b6fb0db6 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:44:49 -0800 Subject: Remove 'static from variables It's unclear why these were static in the first place. --- test/sys/test_aio.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 4f151458..79de3960 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -49,7 +49,7 @@ 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(), @@ -74,7 +74,7 @@ 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(), @@ -250,7 +250,7 @@ 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 @@ -509,7 +509,7 @@ 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(); -- cgit v1.2.3 From 070c0176049744f63c7f553edcd74ba2376f3ec9 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:49:08 -0800 Subject: Use iter::Cloned() instead of closure --- test/sys/test_uio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index 76597790..262874b3 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(); @@ -84,7 +84,7 @@ fn test_readv() { // 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())); + read_buf.extend(iovec.as_slice().iter().cloned()); } // Check whether iovecs contain all written data assert_eq!(read_buf.len(), to_write.len()); -- cgit v1.2.3 From 4bad9bf9b9bb08d29511f060a3adae7453573a72 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:50:47 -0800 Subject: Remove unnecessary .ok() --- test/sys/test_signal.rs | 2 +- test/sys/test_signalfd.rs | 2 +- test/sys/test_wait.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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_wait.rs b/test/sys/test_wait.rs index 02f32734..e834f9f0 100644 --- a/test/sys/test_wait.rs +++ b/test/sys/test_wait.rs @@ -14,7 +14,7 @@ fn test_wait_signal() { match fork() { Ok(Child) => pause().unwrap_or_else(|_| unsafe { _exit(123) }), Ok(Parent { child }) => { - kill(child, Some(SIGKILL)).ok().expect("Error: Kill Failed"); + 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 -- cgit v1.2.3 From d8c538525807253aea6c64fc4bdcdb8a6e24f78d Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 14:58:02 -0800 Subject: Make numeric literals easier to read --- src/sys/event.rs | 4 +-- src/sys/ioctl/platform/bsd.rs | 6 ++--- test/sys/test_ioctl.rs | 60 +++++++++++++++++++++---------------------- test/sys/test_socket.rs | 2 +- test/sys/test_sockopt.rs | 2 +- 5 files changed, 37 insertions(+), 37 deletions(-) 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/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/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs index 1ed4a4b4..26ff42f8 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); } } 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); -- cgit v1.2.3 From 1c9f6c872d0e6e5fcd6a875f484131e1c095cb05 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:01:04 -0800 Subject: Use println!() instead of print!(...n) --- test/test_mount.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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!(); }} } -- cgit v1.2.3 From b93c1adabeb093934263c4f7ed11ac0636de8324 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:10:11 -0800 Subject: Remove unnecessary references --- src/sys/socket/mod.rs | 2 +- test/sys/test_aio.rs | 18 +++++++++--------- test/sys/test_aio_drop.rs | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 8aa65369..0e446713 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -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)))) diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 79de3960..c5f2dbc5 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -54,7 +54,7 @@ fn test_cancel() { 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); @@ -79,7 +79,7 @@ fn test_aio_cancel_all() { 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); @@ -143,7 +143,7 @@ fn test_aio_suspend() { let mut wcb = AioCb::from_slice( f.as_raw_fd(), 2, //offset - &mut WBUF, + WBUF, 0, //priority SigevNotify::SigevNone, LioOpcode::LIO_WRITE); @@ -254,7 +254,7 @@ fn test_read_immutable_buffer() { 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); @@ -339,7 +339,7 @@ fn test_write_sigev_signal() { 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, @@ -376,7 +376,7 @@ fn test_lio_listio_wait() { { let mut wcb = AioCb::from_slice( f.as_raw_fd(), 2, //offset - &WBUF, + WBUF, 0, //priority SigevNotify::SigevNone, LioOpcode::LIO_WRITE); @@ -419,7 +419,7 @@ fn test_lio_listio_nowait() { { let mut wcb = AioCb::from_slice( f.as_raw_fd(), 2, //offset - &WBUF, + WBUF, 0, //priority SigevNotify::SigevNone, LioOpcode::LIO_WRITE); @@ -472,7 +472,7 @@ fn test_lio_listio_signal() { { let mut wcb = AioCb::from_slice( f.as_raw_fd(), 2, //offset - &WBUF, + WBUF, 0, //priority SigevNotify::SigevNone, LioOpcode::LIO_WRITE); @@ -515,7 +515,7 @@ fn test_lio_listio_read_immutable() { 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 9214957f..1f4a3e79 100644 --- a/test/sys/test_aio_drop.rs +++ b/test/sys/test_aio_drop.rs @@ -19,7 +19,7 @@ fn test_drop() { 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); -- cgit v1.2.3 From 7b4402f091ccac878f3cbb772a6df20ba7a7a9e6 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:13:58 -0800 Subject: Use Rc::clone() instead of .clone() Makes it more clear what's being cloned --- test/sys/test_aio.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index c5f2dbc5..e84d95b5 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -150,7 +150,7 @@ fn test_aio_suspend() { 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); @@ -184,7 +184,7 @@ fn test_read() { { 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); @@ -211,7 +211,7 @@ fn test_read_error() { 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); @@ -383,7 +383,7 @@ fn test_lio_listio_wait() { 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); @@ -426,7 +426,7 @@ fn test_lio_listio_nowait() { 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); @@ -479,7 +479,7 @@ fn test_lio_listio_signal() { 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); -- cgit v1.2.3 From 46fe1319a73a9d4c0081c2b5f8900d7943f3a44b Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:22:01 -0800 Subject: Remove useless Err(_) match arms --- test/sys/test_ptrace.rs | 7 +++--- test/sys/test_uio.rs | 7 +++--- test/sys/test_wait.rs | 23 +++++++----------- test/test_stat.rs | 62 +++++++++++++++++++++---------------------------- test/test_unistd.rs | 17 +++++--------- 5 files changed, 48 insertions(+), 68 deletions(-) diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index d3e579f3..f31ba877 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -66,8 +66,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 +76,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 +86,5 @@ fn test_ptrace_cont() { _ => panic!("The process should have been killed"), } }, - Err(_) => panic!("Error: Fork Failed") } } diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index 262874b3..8c326a38 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -208,8 +208,8 @@ 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 [0u8]).unwrap(); @@ -229,7 +229,7 @@ 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() { *i += 1; @@ -238,6 +238,5 @@ fn test_process_vm_readv() { 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 e834f9f0..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 }) => { + 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_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) { - 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) { - 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 7c26210c..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") } } -- cgit v1.2.3 From ee75274b2ad3ccbc8005ef438accd96f6e237443 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:37:20 -0800 Subject: Correct ioctl read and write_ptr tests Looks like a copy/paste error might have caused this --- test/sys/test_ioctl.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs index 26ff42f8..57ca9177 100644 --- a/test/sys/test_ioctl.rs +++ b/test/sys/test_ioctl.rs @@ -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) }; -- cgit v1.2.3 From a6b394ee4caf8e1b7d3eadf4ffc0429ea461889c Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:37:31 -0800 Subject: Remove unnecessary mut --- test/sys/test_ioctl.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs index 57ca9177..9a7a4819 100644 --- a/test/sys/test_ioctl.rs +++ b/test/sys/test_ioctl.rs @@ -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))); } -- cgit v1.2.3 From b814db046aed7a0a683d4f14e622a721ddcff8cb Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:38:40 -0800 Subject: Use '!' instead of '== false' Reads a little bit easier --- test/sys/test_aio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index e84d95b5..1f807585 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -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)); } @@ -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)); } -- cgit v1.2.3 From d203e92ad7e2d17935bc81fdf0082eebe0ab5ebe Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:49:50 -0800 Subject: Remove match statements with one arm --- test/sys/test_ptrace.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index f31ba877..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!"); } } -- cgit v1.2.3 From 0d6770baf3901f98a2203051860011beb663ee84 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Fri, 15 Dec 2017 15:51:43 -0800 Subject: Remove uses of .iter()/.iter_mut() More Rusty to use &X and &mut X where X is a container type. --- test/sys/test_uio.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index 8c326a38..c6331f1d 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -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,7 +83,7 @@ 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() { + for iovec in &iovecs { read_buf.extend(iovec.as_slice().iter().cloned()); } // Check whether iovecs contain all written data @@ -231,7 +231,7 @@ fn test_process_vm_readv() { }, Child => { let _ = close(r); - for i in vector.iter_mut() { + for i in &mut vector { *i += 1; } let _ = write(w, b"\0"); -- cgit v1.2.3 From d53ec4c6776daf18dff54991cd474256253ac7d8 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 08:57:19 -0800 Subject: Merge redundant match arms --- src/errno.rs | 6 ------ src/sys/signalfd.rs | 3 +-- src/sys/socket/addr.rs | 3 +-- src/sys/wait.rs | 13 ++++--------- 4 files changed, 6 insertions(+), 19 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/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 { 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..0130d2c0 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -750,8 +750,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, } } } 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 { 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), } } } -- cgit v1.2.3 From a46ff3c413b913b5a8714638370c23aa9abff519 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:04:55 -0800 Subject: Make numeric literals easier to read --- src/sys/stat.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 9c0129f5..38c785ed 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -53,22 +53,22 @@ pub fn mknod(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 { -- cgit v1.2.3 From 7ad86e19aac01c048f1e2668ed0944228e53c524 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:13:05 -0800 Subject: Remove unnecessary parenthesis --- src/sys/socket/mod.rs | 2 +- src/sys/stat.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 0e446713..d2c77ff6 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1037,7 +1037,7 @@ pub unsafe fn sockaddr_storage_to_addr( } libc::AF_INET6 => { assert!(len as usize == mem::size_of::()); - 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 38c785ed..1f0d728a 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -68,7 +68,7 @@ pub fn makedev(major: u64, minor: u64) -> dev_t { ((major & 0xffff_f000) << 32) | ((major & 0x0000_0fff) << 8) | ((minor & 0xffff_ff00) << 12) | - ((minor & 0x0000_00ff) ) + (minor & 0x0000_00ff) } pub fn umask(mode: Mode) -> Mode { -- cgit v1.2.3 From 9acfff7ab09fd83246a057b6b06bd0a3834b1fe5 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:16:16 -0800 Subject: Use unwrap_or_else instead of unwrap_or without a closure --- src/sys/socket/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index d2c77ff6..049965e5 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) -> 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, }) } } -- cgit v1.2.3 From 0691ed1383ad50b9cf0d95561b908b7fadf2295e Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:19:14 -0800 Subject: Remove unnecessary .into() --- src/pty.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pty.rs b/src/pty.rs index d526ed17..09c30cf4 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -69,7 +69,7 @@ impl Drop for PtyMaster { #[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(()) @@ -116,7 +116,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result { }; if fd < 0 { - return Err(Error::last().into()); + return Err(Error::last()); } Ok(PtyMaster(fd)) @@ -142,7 +142,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result { pub unsafe fn ptsname(fd: &PtyMaster) -> Result { 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); @@ -164,7 +164,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result { 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 @@ -185,7 +185,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result { #[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(()) -- cgit v1.2.3 From f91586f4519a2ec1af9fddc7e667ba0b9a22d579 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:22:53 -0800 Subject: Dereference in match head instead --- src/lib.rs | 20 ++++++++++---------- src/sys/signal.rs | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) 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 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/sys/signal.rs b/src/sys/signal.rs index f82e4502..0642a691 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, @@ -560,8 +560,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 }; } -- cgit v1.2.3 From b4a7983288ad53812ac84a7f6196071600d39ec7 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:37:25 -0800 Subject: Remove unnecessary lifetime annotations --- src/fcntl.rs | 3 +-- src/sys/uio.rs | 2 +- src/sys/utsname.rs | 10 +++++----- src/unistd.rs | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) 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(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/sys/uio.rs b/src/sys/uio.rs index c785225b..391fb25e 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -141,7 +141,7 @@ pub struct IoVec(libc::iovec, PhantomData); impl IoVec { #[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..2765a038 100644 --- a/src/sys/utsname.rs +++ b/src/sys/utsname.rs @@ -11,23 +11,23 @@ pub struct UtsName(libc::utsname); 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/unistd.rs b/src/unistd.rs index 7a1c56c7..acabdf0c 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -748,7 +748,7 @@ pub fn sethostname>(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; -- cgit v1.2.3 From 86d1801922cd6532d17939abad17db191db5c752 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:48:35 -0800 Subject: Remove unnecessary impl Clones --- src/sys/socket/addr.rs | 32 ++++---------------------------- src/sys/utsname.rs | 5 +---- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 0130d2c0..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), @@ -802,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/utsname.rs b/src/sys/utsname.rs index 2765a038..afec3e20 100644 --- a/src/sys/utsname.rs +++ b/src/sys/utsname.rs @@ -4,12 +4,9 @@ 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(&self) -> &str { to_str(&(&self.0.sysname as *const c_char ) as *const *const c_char) -- cgit v1.2.3 From 31366291b8bfbf06df8c2bca9e0f16f163605bd5 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:54:17 -0800 Subject: Use |= where appropriate --- src/sys/socket/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 049965e5..1e84854f 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -689,7 +689,7 @@ pub fn socket>>(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>>(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 { -- cgit v1.2.3 From 7d0058222566b14c07c7422d6212e0e789e565e1 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 09:56:54 -0800 Subject: Remove unnecessary '@ _' --- src/sys/termios.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 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), } } } -- cgit v1.2.3 From 7e7a9ed321c7a173cacaac7647e21dbe119a6eb7 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 10:17:21 -0800 Subject: Use implicit returns --- src/sys/aio.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) 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, -- cgit v1.2.3 From 7c1fe907ccd97d84e55912e85fd0fcf88760864c Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 10:24:47 -0800 Subject: Use backticks around types/functions in docs --- src/mqueue.rs | 12 ++++++------ src/pty.rs | 12 ++++++------ src/sys/ioctl/mod.rs | 2 +- src/sys/pthread.rs | 6 +++--- src/sys/ptrace.rs | 2 +- src/sys/signal.rs | 4 ++-- src/sys/socket/mod.rs | 4 ++-- src/sys/uio.rs | 10 +++++----- src/unistd.rs | 6 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) 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 { 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 { let mut attr = unsafe { mem::uninitialized::() }; let res = unsafe { libc::mq_getattr(mqd, &mut attr) }; diff --git a/src/pty.rs b/src/pty.rs index 09c30cf4..ea0e543d 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -62,7 +62,7 @@ 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. @@ -76,7 +76,7 @@ pub fn grantpt(fd: &PtyMaster) -> Result<()> { } /// 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. /// @@ -123,7 +123,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result { } /// 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`. @@ -150,7 +150,7 @@ pub unsafe fn ptsname(fd: &PtyMaster) -> Result { } /// 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 @@ -177,7 +177,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result { } /// 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 @@ -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/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/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(request: Request, pid: Pid) -> Result { diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 0642a691..b6a8f2f8 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -423,8 +423,8 @@ pub unsafe fn sigaction(signal: Signal, sigaction: &SigAction) -> Result, oldset: Option<&mut SigSet>) -> Result<()> { diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 1e84854f..11e7a1af 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1015,9 +1015,9 @@ pub fn getsockname(fd: RawFd) -> Result { } } -/// 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. diff --git a/src/sys/uio.rs b/src/sys/uio.rs index 391fb25e..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{ /// /// 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"))] diff --git a/src/unistd.rs b/src/unistd.rs index acabdf0c..56390d90 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -480,7 +480,7 @@ pub fn mkfifo(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>(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 @@ -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 -- cgit v1.2.3 From 48aa9c8f88c5665a1d510c32cb3fc8362d35024a Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 10:32:19 -0800 Subject: Replace '0 as *_' with ptr::null*() --- src/sys/socket/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 11e7a1af..0c7fbb97 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -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(); -- cgit v1.2.3 From 565b7fef2b9e00c10c088af7444fba3ecaf39854 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 10:34:25 -0800 Subject: Remove redundant closure --- src/sys/signal.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/signal.rs b/src/sys/signal.rs index b6a8f2f8..94d88df2 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -435,9 +435,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::(), + set.map_or_else(ptr::null::, |s| &s.sigset as *const libc::sigset_t), - oldset.map_or_else(|| ptr::null_mut::(), + oldset.map_or_else(ptr::null_mut::, |os| &mut os.sigset as *mut libc::sigset_t)) }; -- cgit v1.2.3 From 68baedc06adfbb59533afdf11d60e84f12d2a01e Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 10:38:41 -0800 Subject: Don't clone Copy types --- src/sys/signal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 94d88df2..78ae87c9 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -599,7 +599,7 @@ mod sigevent { impl<'a> From<&'a libc::sigevent> for SigEvent { fn from(sigevent: &libc::sigevent) -> Self { - SigEvent{ sigevent: sigevent.clone() } + SigEvent{ sigevent: *sigevent } } } } -- cgit v1.2.3 From 8db68be6ba9c25c0955f4febeb78b31030ba7603 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 16 Dec 2017 10:42:55 -0800 Subject: Replace boolean match with if/else --- src/sys/signal.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 78ae87c9..d295abcc 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -191,9 +191,10 @@ impl Signal { // implemented, we'll replace this function. #[inline] pub fn from_c_int(signum: libc::c_int) -> Result { - 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()) } } } -- cgit v1.2.3