Skip to content

Clippy cleanup #818

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
149d6c1
Use write_all instead of write
Dec 15, 2017
73ea706
Use byte strings instead of String.as_bytes()
Dec 15, 2017
68859b9
Add backticks to types in doccomments
Dec 15, 2017
09a79fa
Remove useless vec![]
Dec 15, 2017
ae8e4a4
Remove elided 'static lifetime
Dec 15, 2017
e831466
Remove 'static from variables
Dec 15, 2017
070c017
Use iter::Cloned() instead of closure
Dec 15, 2017
4bad9bf
Remove unnecessary .ok()
Dec 15, 2017
d8c5385
Make numeric literals easier to read
Dec 15, 2017
1c9f6c8
Use println!() instead of print!(...n)
Dec 15, 2017
b93c1ad
Remove unnecessary references
Dec 15, 2017
7b4402f
Use Rc::clone() instead of .clone()
Dec 15, 2017
46fe131
Remove useless Err(_) match arms
Dec 15, 2017
ee75274
Correct ioctl read and write_ptr tests
Dec 15, 2017
a6b394e
Remove unnecessary mut
Dec 15, 2017
b814db0
Use '!' instead of '== false'
Dec 15, 2017
d203e92
Remove match statements with one arm
Dec 15, 2017
0d6770b
Remove uses of .iter()/.iter_mut()
Dec 15, 2017
d53ec4c
Merge redundant match arms
Dec 16, 2017
a46ff3c
Make numeric literals easier to read
Dec 16, 2017
7ad86e1
Remove unnecessary parenthesis
Dec 16, 2017
9acfff7
Use unwrap_or_else instead of unwrap_or without a closure
Dec 16, 2017
0691ed1
Remove unnecessary .into()
Dec 16, 2017
f91586f
Dereference in match head instead
Dec 16, 2017
b4a7983
Remove unnecessary lifetime annotations
Dec 16, 2017
86d1801
Remove unnecessary impl Clones
Dec 16, 2017
3136629
Use |= where appropriate
Dec 16, 2017
7d00582
Remove unnecessary '@ _'
Dec 16, 2017
7e7a9ed
Use implicit returns
Dec 16, 2017
7c1fe90
Use backticks around types/functions in docs
Dec 16, 2017
48aa9c8
Replace '0 as *_' with ptr::null*()
Dec 16, 2017
565b7fe
Remove redundant closure
Dec 16, 2017
68baedc
Don't clone Copy types
Dec 16, 2017
8db68be
Replace boolean match with if/else
Dec 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ mod consts {
use self::Errno::*;

match e {
0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
Expand Down Expand Up @@ -940,7 +939,6 @@ mod consts {
use self::Errno::*;

match e {
0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
Expand Down Expand Up @@ -1168,7 +1166,6 @@ mod consts {
use self::Errno::*;

match e {
0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
Expand Down Expand Up @@ -1391,7 +1388,6 @@ mod consts {
use self::Errno::*;

match e {
0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
Expand Down Expand Up @@ -1607,7 +1603,6 @@ mod consts {
use self::Errno::*;

match e {
0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
Expand Down Expand Up @@ -1819,7 +1814,6 @@ mod consts {
use self::Errno::*;

match e {
0 => UnknownErrno,
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
Expand Down
3 changes: 1 addition & 2 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -86,23 +86,23 @@ 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)
}

/// 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)
}

/// 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 {
Expand All @@ -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,
Expand All @@ -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) };
Expand Down
22 changes: 11 additions & 11 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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`.
Expand All @@ -142,15 +142,15 @@ 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);
Ok(name.to_string_lossy().into_owned())
}

/// 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
Expand All @@ -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
Expand All @@ -177,15 +177,15 @@ 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
/// pseuoterminal.
#[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(())
Expand All @@ -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
Expand Down
36 changes: 24 additions & 12 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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`.
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/sys/ioctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
Expand Down
6 changes: 3 additions & 3 deletions src/sys/ioctl/platform/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions src/sys/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
2 changes: 1 addition & 1 deletion src/sys/ptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Loading