diff options
author | Alan Somers <asomers@gmail.com> | 2019-08-19 15:55:25 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2019-08-29 10:06:02 -0600 |
commit | 417e91363a25c663ff884f3dcb879832bf0a66ed (patch) | |
tree | e4643f14f1701edc48d0818ef1b4707377f77612 /src | |
parent | faaacf959a47f286306ae73a2b24a649e2249199 (diff) | |
download | nix-417e91363a25c663ff884f3dcb879832bf0a66ed.zip |
Clippy cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/dir.rs | 6 | ||||
-rw-r--r-- | src/errno.rs | 4 | ||||
-rw-r--r-- | src/fcntl.rs | 6 | ||||
-rw-r--r-- | src/ifaddrs.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 36 | ||||
-rw-r--r-- | src/macros.rs | 2 | ||||
-rw-r--r-- | src/mqueue.rs | 4 | ||||
-rw-r--r-- | src/poll.rs | 4 | ||||
-rw-r--r-- | src/pty.rs | 8 | ||||
-rw-r--r-- | src/sys/aio.rs | 1 | ||||
-rw-r--r-- | src/sys/event.rs | 2 | ||||
-rw-r--r-- | src/sys/sendfile.rs | 4 | ||||
-rw-r--r-- | src/sys/signal.rs | 4 | ||||
-rw-r--r-- | src/sys/socket/addr.rs | 63 | ||||
-rw-r--r-- | src/sys/socket/mod.rs | 54 | ||||
-rw-r--r-- | src/sys/socket/sockopt.rs | 2 | ||||
-rw-r--r-- | src/sys/time.rs | 8 | ||||
-rw-r--r-- | src/sys/wait.rs | 2 | ||||
-rw-r--r-- | src/unistd.rs | 24 |
19 files changed, 138 insertions, 100 deletions
@@ -107,11 +107,11 @@ impl<'d> Iterator for Iter<'d> { if let Err(e) = Errno::result(readdir_r((self.0).0.as_ptr(), &mut ent.0, &mut result)) { return Some(Err(e)); } - if result == ptr::null_mut() { + if result.is_null() { return None; } assert_eq!(result, &mut ent.0 as *mut dirent); - return Some(Ok(ent)); + Some(Ok(ent)) } } } @@ -165,7 +165,7 @@ impl Entry { target_os = "macos", target_os = "solaris")))] pub fn ino(&self) -> u64 { - self.0.d_fileno as u64 + u64::from(self.0.d_fileno) } /// Returns the bare file name of this directory entry without any other leading path component. diff --git a/src/errno.rs b/src/errno.rs index 6a2447bc..287bbea4 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -46,7 +46,7 @@ cfg_if! { } /// Sets the platform-specific errno to no-error -unsafe fn clear() -> () { +unsafe fn clear() { *errno_location() = 0; } @@ -70,7 +70,7 @@ impl Errno { from_i32(err) } - pub unsafe fn clear() -> () { + pub unsafe fn clear() { clear() } diff --git a/src/fcntl.rs b/src/fcntl.rs index 08c339a9..7ccb7376 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -152,7 +152,8 @@ libc_bitflags!( pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> { let fd = path.with_nix_path(|cstr| { - unsafe { libc::open(cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) } + let modebits = c_uint::from(mode.bits()); + unsafe { libc::open(cstr.as_ptr(), oflag.bits(), modebits) } })?; Errno::result(fd) @@ -160,7 +161,8 @@ pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<R pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> { let fd = path.with_nix_path(|cstr| { - unsafe { libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) } + let modebits = c_uint::from(mode.bits()); + unsafe { libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), modebits) } })?; Errno::result(fd) } diff --git a/src/ifaddrs.rs b/src/ifaddrs.rs index 12b59bcc..0485b1bb 100644 --- a/src/ifaddrs.rs +++ b/src/ifaddrs.rs @@ -52,8 +52,8 @@ impl InterfaceAddress { let mut addr = InterfaceAddress { interface_name: ifname.to_string_lossy().to_string(), flags: InterfaceFlags::from_bits_truncate(info.ifa_flags as i32), - address: address, - netmask: netmask, + address, + netmask, broadcast: None, destination: None, }; @@ -121,9 +121,9 @@ impl Error { /// let e = Error::from(Errno::EPERM); /// assert_eq!(Some(Errno::EPERM), e.as_errno()); /// ``` - pub fn as_errno(&self) -> Option<Errno> { - if let &Error::Sys(ref e) = self { - Some(*e) + pub fn as_errno(self) -> Option<Errno> { + if let Error::Sys(e) = self { + Some(e) } else { None } @@ -177,6 +177,8 @@ impl fmt::Display for Error { } pub trait NixPath { + fn is_empty(&self) -> bool; + fn len(&self) -> usize; fn with_nix_path<T, F>(&self, f: F) -> Result<T> @@ -184,6 +186,10 @@ pub trait NixPath { } impl NixPath for str { + fn is_empty(&self) -> bool { + NixPath::is_empty(OsStr::new(self)) + } + fn len(&self) -> usize { NixPath::len(OsStr::new(self)) } @@ -195,6 +201,10 @@ impl NixPath for str { } impl NixPath for OsStr { + fn is_empty(&self) -> bool { + self.as_bytes().is_empty() + } + fn len(&self) -> usize { self.as_bytes().len() } @@ -206,6 +216,10 @@ impl NixPath for OsStr { } impl NixPath for CStr { + fn is_empty(&self) -> bool { + self.to_bytes().is_empty() + } + fn len(&self) -> usize { self.to_bytes().len() } @@ -222,6 +236,10 @@ impl NixPath for CStr { } impl NixPath for [u8] { + fn is_empty(&self) -> bool { + self.is_empty() + } + fn len(&self) -> usize { self.len() } @@ -249,6 +267,10 @@ impl NixPath for [u8] { } impl NixPath for Path { + fn is_empty(&self) -> bool { + NixPath::is_empty(self.as_os_str()) + } + fn len(&self) -> usize { NixPath::len(self.as_os_str()) } @@ -259,6 +281,10 @@ impl NixPath for Path { } impl NixPath for PathBuf { + fn is_empty(&self) -> bool { + NixPath::is_empty(self.as_os_str()) + } + fn len(&self) -> usize { NixPath::len(self.as_os_str()) } @@ -270,6 +296,10 @@ impl NixPath for PathBuf { /// Treats `None` as an empty string. impl<'a, NP: ?Sized + NixPath> NixPath for Option<&'a NP> { + fn is_empty(&self) -> bool { + self.map_or(true, NixPath::is_empty) + } + fn len(&self) -> usize { self.map_or(0, NixPath::len) } diff --git a/src/macros.rs b/src/macros.rs index 3d1b0e4b..7ec00c86 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -259,6 +259,6 @@ macro_rules! libc_enum { /// offset of `field` within struct `ty` macro_rules! offset_of { ($ty:ty, $field:ident) => { - &(*(0 as *const $ty)).$field as *const _ as usize + &(*(ptr::null() as *const $ty)).$field as *const _ as usize } } diff --git a/src/mqueue.rs b/src/mqueue.rs index b958b71c..a35f895b 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -57,6 +57,8 @@ impl MqAttr { /// Open a message queue /// /// See also [`mq_open(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html) +// The mode.bits cast is only lossless on some OSes +#[allow(clippy::cast_lossless)] pub fn mq_open(name: &CString, oflag: MQ_OFlag, mode: Mode, @@ -142,7 +144,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> { /// Returns the old attributes pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> { let oldattr = mq_getattr(mqd)?; - let newattr = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long, + let newattr = MqAttr::new(c_long::from(MQ_OFlag::O_NONBLOCK.bits()), oldattr.mq_attr.mq_maxmsg, oldattr.mq_attr.mq_msgsize, oldattr.mq_attr.mq_curmsgs); diff --git a/src/poll.rs b/src/poll.rs index c603611e..15bafe2d 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -29,7 +29,7 @@ impl PollFd { pub fn new(fd: RawFd, events: PollFlags) -> PollFd { PollFd { pollfd: libc::pollfd { - fd: fd, + fd, events: events.bits(), revents: PollFlags::empty().bits(), }, @@ -37,7 +37,7 @@ impl PollFd { } /// Returns the events that occured in the last call to `poll` or `ppoll`. - pub fn revents(&self) -> Option<PollFlags> { + pub fn revents(self) -> Option<PollFlags> { PollFlags::from_bits(self.pollfd.revents) } } @@ -274,8 +274,8 @@ pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios> Errno::result(ret)?; Ok(OpenptyResult { - master: master, - slave: slave, + master, + slave, }) } @@ -319,8 +319,8 @@ pub fn forkpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios> })?; Ok(ForkptyResult { - master: master, - fork_result: fork_result, + master, + fork_result, }) } diff --git a/src/sys/aio.rs b/src/sys/aio.rs index 9258a065..dc2663ca 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -1213,7 +1213,6 @@ impl<'a> LioCb<'a> { }, Err(Error::Sys(Errno::EINPROGRESS)) => { // aiocb is was successfully queued; no need to do anything - () }, Err(Error::Sys(Errno::EINVAL)) => panic!( "AioCb was never submitted, or already finalized"), diff --git a/src/sys/event.rs b/src/sys/event.rs index 8cd7372f..882223bd 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -234,7 +234,7 @@ impl KEvent { pub fn new(ident: uintptr_t, filter: EventFilter, flags: EventFlag, fflags:FilterFlag, data: intptr_t, udata: intptr_t) -> KEvent { KEvent { kevent: libc::kevent { - ident: ident, + ident, filter: filter as type_of_event_filter, flags: flags.bits(), fflags: fflags.bits(), diff --git a/src/sys/sendfile.rs b/src/sys/sendfile.rs index a47d8962..1618558a 100644 --- a/src/sys/sendfile.rs +++ b/src/sys/sendfile.rs @@ -123,6 +123,7 @@ cfg_if! { /// /// For more information, see /// [the sendfile(2) man page.](https://www.freebsd.org/cgi/man.cgi?query=sendfile&sektion=2) + #[allow(clippy::too_many_arguments)] pub fn sendfile( in_fd: RawFd, out_sock: RawFd, @@ -136,7 +137,8 @@ cfg_if! { // Readahead goes in upper 16 bits // Flags goes in lower 16 bits // see `man 2 sendfile` - let flags: u32 = ((readahead as u32) << 16) | (flags.bits() as u32); + let ra32 = u32::from(readahead); + let flags: u32 = (ra32 << 16) | (flags.bits() as u32); let mut bytes_sent: off_t = 0; let hdtr = headers.or(trailers).map(|_| SendfileHeaderTrailer::new(headers, trailers)); let hdtr_ptr = hdtr.as_ref().map_or(ptr::null(), |s| &s.0 as *const libc::sf_hdtr); diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 1013a77f..51df7b12 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -338,14 +338,14 @@ impl SigSet { let mut sigset: libc::sigset_t = unsafe { mem::uninitialized() }; let _ = unsafe { libc::sigfillset(&mut sigset as *mut libc::sigset_t) }; - SigSet { sigset: sigset } + SigSet { sigset } } pub fn empty() -> SigSet { let mut sigset: libc::sigset_t = unsafe { mem::uninitialized() }; let _ = unsafe { libc::sigemptyset(&mut sigset as *mut libc::sigset_t) }; - SigSet { sigset: sigset } + SigSet { sigset } } pub fn add(&mut self, signal: Signal) { diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index ed414411..1c6f1b54 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -367,6 +367,8 @@ impl IpAddr { /// Create a new IpAddr that contains an IPv6 address. /// /// The result will represent the IP address a:b:c:d:e:f + #[allow(clippy::many_single_char_names)] + #[allow(clippy::too_many_arguments)] pub fn new_v6(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> IpAddr { IpAddr::V6(Ipv6Addr::new(a, b, c, d, e, f, g, h)) } @@ -405,15 +407,18 @@ impl fmt::Display for IpAddr { pub struct Ipv4Addr(pub libc::in_addr); impl Ipv4Addr { + #[allow(clippy::identity_op)] // More readable this way pub fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { - let ip = (((a as u32) << 24) | - ((b as u32) << 16) | - ((c as u32) << 8) | - ((d as u32) << 0)).to_be(); + let ip = ((u32::from(a) << 24) | + (u32::from(b) << 16) | + (u32::from(c) << 8) | + (u32::from(d) << 0)).to_be(); Ipv4Addr(libc::in_addr { s_addr: ip }) } + // Use pass by reference for symmetry with Ipv6Addr::from_std + #[allow(clippy::trivially_copy_pass_by_ref)] pub fn from_std(std: &net::Ipv4Addr) -> Ipv4Addr { let bits = std.octets(); Ipv4Addr::new(bits[0], bits[1], bits[2], bits[3]) @@ -423,12 +428,12 @@ impl Ipv4Addr { Ipv4Addr(libc::in_addr { s_addr: libc::INADDR_ANY }) } - pub fn octets(&self) -> [u8; 4] { + pub fn octets(self) -> [u8; 4] { let bits = u32::from_be(self.0.s_addr); [(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8] } - pub fn to_std(&self) -> net::Ipv4Addr { + pub fn to_std(self) -> net::Ipv4Addr { let bits = self.octets(); net::Ipv4Addr::new(bits[0], bits[1], bits[2], bits[3]) } @@ -467,6 +472,8 @@ macro_rules! to_u16_array { } impl Ipv6Addr { + #[allow(clippy::many_single_char_names)] + #[allow(clippy::too_many_arguments)] pub fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { let mut in6_addr_var: libc::in6_addr = unsafe{mem::uninitialized()}; in6_addr_var.s6_addr = to_u8_array!(a,b,c,d,e,f,g,h); @@ -713,7 +720,7 @@ impl SockAddr { if addr.is_null() { None } else { - match AddressFamily::from_i32((*addr).sa_family as i32) { + match AddressFamily::from_i32(i32::from((*addr).sa_family)) { Some(AddressFamily::Unix) => None, Some(AddressFamily::Inet) => Some(SockAddr::Inet( InetAddr::V4(*(addr as *const libc::sockaddr_in)))), @@ -957,7 +964,7 @@ pub mod sys_control { let mut ctl_name = [0; MAX_KCTL_NAME]; ctl_name[..name.len()].clone_from_slice(name.as_bytes()); - let mut info = ctl_ioc_info { ctl_id: 0, ctl_name: ctl_name }; + let mut info = ctl_ioc_info { ctl_id: 0, ctl_name }; unsafe { ctl_info(sockfd, &mut info)?; } @@ -1023,14 +1030,14 @@ mod datalink { /// Physical-layer address (MAC) pub fn addr(&self) -> [u8; 6] { - let a = self.0.sll_addr[0] as u8; - let b = self.0.sll_addr[1] as u8; - let c = self.0.sll_addr[2] as u8; - let d = self.0.sll_addr[3] as u8; - let e = self.0.sll_addr[4] as u8; - let f = self.0.sll_addr[5] as u8; - - [a, b, c, d, e, f] + [ + self.0.sll_addr[0] as u8, + self.0.sll_addr[1] as u8, + self.0.sll_addr[2] as u8, + self.0.sll_addr[3] as u8, + self.0.sll_addr[4] as u8, + self.0.sll_addr[5] as u8, + ] } } @@ -1069,7 +1076,7 @@ mod datalink { /// always == AF_LINK pub fn family(&self) -> AddressFamily { - assert_eq!(self.0.sdl_family as i32, libc::AF_LINK); + assert_eq!(i32::from(self.0.sdl_family), libc::AF_LINK); AddressFamily::Link } @@ -1105,11 +1112,7 @@ mod datalink { let alen = self.alen(); let data_len = self.0.sdl_data.len(); - if alen > 0 && nlen + alen < data_len { - false - } else { - true - } + alen == 0 || nlen + alen >= data_len } /// Physical-layer address (MAC) @@ -1119,14 +1122,14 @@ mod datalink { assert!(!self.is_empty()); - let a = data[nlen] as u8; - let b = data[nlen + 1] as u8; - let c = data[nlen + 2] as u8; - let d = data[nlen + 3] as u8; - let e = data[nlen + 4] as u8; - let f = data[nlen + 5] as u8; - - [a, b, c, d, e, f] + [ + data[nlen] as u8, + data[nlen + 1] as u8, + data[nlen + 2] as u8, + data[nlen + 3] as u8, + data[nlen + 4] as u8, + data[nlen + 5] as u8, + ] } } diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 1c12c5f8..0bb7b2f3 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -553,11 +553,10 @@ impl ControlMessageOwned { let n = len / mem::size_of::<RawFd>(); let mut fds = Vec::with_capacity(n); for i in 0..n { - let fdp = (p as *const RawFd).offset(i as isize); + let fdp = (p as *const RawFd).add(i); fds.push(ptr::read_unaligned(fdp)); } - let cmo = ControlMessageOwned::ScmRights(fds); - cmo + ControlMessageOwned::ScmRights(fds) }, #[cfg(any(target_os = "android", target_os = "linux"))] (libc::SOL_SOCKET, libc::SCM_CREDENTIALS) => { @@ -715,16 +714,16 @@ impl<'a> ControlMessage<'a> { /// Return a reference to the payload data as a byte pointer fn copy_to_cmsg_data(&self, cmsg_data: *mut u8) { - let data_ptr = match self { - &ControlMessage::ScmRights(fds) => { + let data_ptr = match *self { + ControlMessage::ScmRights(fds) => { fds as *const _ as *const u8 }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::ScmCredentials(creds) => { + ControlMessage::ScmCredentials(creds) => { creds as *const libc::ucred as *const u8 } #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetIv(iv) => { + ControlMessage::AlgSetIv(iv) => { unsafe { let alg_iv = cmsg_data as *mut libc::af_alg_iv; (*alg_iv).ivlen = iv.len() as u32; @@ -737,11 +736,11 @@ impl<'a> ControlMessage<'a> { return }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetOp(op) => { + ControlMessage::AlgSetOp(op) => { op as *const _ as *const u8 }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetAeadAssoclen(len) => { + ControlMessage::AlgSetAeadAssoclen(len) => { len as *const _ as *const u8 }, }; @@ -756,24 +755,24 @@ impl<'a> ControlMessage<'a> { /// The size of the payload, excluding its cmsghdr fn len(&self) -> usize { - match self { - &ControlMessage::ScmRights(fds) => { + match *self { + ControlMessage::ScmRights(fds) => { mem::size_of_val(fds) }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::ScmCredentials(creds) => { + ControlMessage::ScmCredentials(creds) => { mem::size_of_val(creds) } #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetIv(iv) => { + ControlMessage::AlgSetIv(iv) => { mem::size_of::<libc::af_alg_iv>() + iv.len() }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetOp(op) => { + ControlMessage::AlgSetOp(op) => { mem::size_of_val(op) }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetAeadAssoclen(len) => { + ControlMessage::AlgSetAeadAssoclen(len) => { mem::size_of_val(len) }, } @@ -781,33 +780,32 @@ impl<'a> ControlMessage<'a> { /// Returns the value to put into the `cmsg_level` field of the header. fn cmsg_level(&self) -> libc::c_int { - match self { - &ControlMessage::ScmRights(_) => libc::SOL_SOCKET, + match *self { + ControlMessage::ScmRights(_) => libc::SOL_SOCKET, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::ScmCredentials(_) => libc::SOL_SOCKET, + ControlMessage::ScmCredentials(_) => libc::SOL_SOCKET, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetIv(_) | &ControlMessage::AlgSetOp(_) | &ControlMessage::AlgSetAeadAssoclen(_) => { - libc::SOL_ALG - }, + ControlMessage::AlgSetIv(_) | ControlMessage::AlgSetOp(_) | + ControlMessage::AlgSetAeadAssoclen(_) => libc::SOL_ALG , } } /// Returns the value to put into the `cmsg_type` field of the header. fn cmsg_type(&self) -> libc::c_int { - match self { - &ControlMessage::ScmRights(_) => libc::SCM_RIGHTS, + match *self { + ControlMessage::ScmRights(_) => libc::SCM_RIGHTS, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::ScmCredentials(_) => libc::SCM_CREDENTIALS, + ControlMessage::ScmCredentials(_) => libc::SCM_CREDENTIALS, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetIv(_) => { + ControlMessage::AlgSetIv(_) => { libc::ALG_SET_IV }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetOp(_) => { + ControlMessage::AlgSetOp(_) => { libc::ALG_SET_OP }, #[cfg(any(target_os = "android", target_os = "linux"))] - &ControlMessage::AlgSetAeadAssoclen(_) => { + ControlMessage::AlgSetAeadAssoclen(_) => { libc::ALG_SET_AEAD_ASSOCLEN }, } @@ -1231,7 +1229,7 @@ pub unsafe fn sockaddr_storage_to_addr( return Err(Error::Sys(Errno::ENOTCONN)); } - match addr.ss_family as c_int { + match c_int::from(addr.ss_family) { libc::AF_INET => { assert!(len as usize == mem::size_of::<sockaddr_in>()); let ret = *(addr as *const _ as *const sockaddr_in); diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index a9960100..1271f645 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -423,7 +423,7 @@ struct SetStruct<'a, T: 'static> { unsafe impl<'a, T> Set<'a, T> for SetStruct<'a, T> { fn new(ptr: &'a T) -> SetStruct<'a, T> { - SetStruct { ptr: ptr } + SetStruct { ptr } } fn ffi_ptr(&self) -> *const c_void { diff --git a/src/sys/time.rs b/src/sys/time.rs index 3ad57543..606bbd9d 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -191,7 +191,7 @@ impl ops::Mul<i32> for TimeSpec { type Output = TimeSpec; fn mul(self, rhs: i32) -> TimeSpec { - let usec = self.num_nanoseconds().checked_mul(rhs as i64) + let usec = self.num_nanoseconds().checked_mul(i64::from(rhs)) .expect("TimeSpec multiply out of bounds"); TimeSpec::nanoseconds(usec) @@ -202,7 +202,7 @@ impl ops::Div<i32> for TimeSpec { type Output = TimeSpec; fn div(self, rhs: i32) -> TimeSpec { - let usec = self.num_nanoseconds() / rhs as i64; + let usec = self.num_nanoseconds() / i64::from(rhs); TimeSpec::nanoseconds(usec) } } @@ -386,7 +386,7 @@ impl ops::Mul<i32> for TimeVal { type Output = TimeVal; fn mul(self, rhs: i32) -> TimeVal { - let usec = self.num_microseconds().checked_mul(rhs as i64) + let usec = self.num_microseconds().checked_mul(i64::from(rhs)) .expect("TimeVal multiply out of bounds"); TimeVal::microseconds(usec) @@ -397,7 +397,7 @@ impl ops::Div<i32> for TimeVal { type Output = TimeVal; fn div(self, rhs: i32) -> TimeVal { - let usec = self.num_microseconds() / rhs as i64; + let usec = self.num_microseconds() / i64::from(rhs); TimeVal::microseconds(usec) } } diff --git a/src/sys/wait.rs b/src/sys/wait.rs index c54f7ec5..7b749990 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -222,7 +222,7 @@ pub fn waitpid<P: Into<Option<Pid>>>(pid: P, options: Option<WaitPidFlag>) -> Re let res = unsafe { libc::waitpid( - pid.into().unwrap_or(Pid::from_raw(-1)).into(), + pid.into().unwrap_or_else(|| Pid::from_raw(-1)).into(), &mut status as *mut c_int, option_bits, ) diff --git a/src/unistd.rs b/src/unistd.rs index f422f091..10999651 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -45,12 +45,12 @@ impl Uid { } /// Returns true if the `Uid` represents privileged user - root. (If it equals zero.) - pub fn is_root(&self) -> bool { - *self == ROOT + pub fn is_root(self) -> bool { + self == ROOT } /// Get the raw `uid_t` wrapped by `self`. - pub fn as_raw(&self) -> uid_t { + pub fn as_raw(self) -> uid_t { self.0 } } @@ -94,7 +94,7 @@ impl Gid { } /// Get the raw `gid_t` wrapped by `self`. - pub fn as_raw(&self) -> gid_t { + pub fn as_raw(self) -> gid_t { self.0 } } @@ -135,7 +135,7 @@ impl Pid { } /// Get the raw `pid_t` wrapped by `self`. - pub fn as_raw(&self) -> pid_t { + pub fn as_raw(self) -> pid_t { self.0 } } @@ -168,8 +168,8 @@ impl ForkResult { /// Return `true` if this is the child process of the `fork()` #[inline] - pub fn is_child(&self) -> bool { - match *self { + pub fn is_child(self) -> bool { + match self { ForkResult::Child => true, _ => false } @@ -177,7 +177,7 @@ impl ForkResult { /// Returns `true` if this is the parent process of the `fork()` #[inline] - pub fn is_parent(&self) -> bool { + pub fn is_parent(self) -> bool { !self.is_child() } } @@ -590,8 +590,10 @@ fn chown_raw_ids(owner: Option<Uid>, group: Option<Gid>) -> (libc::uid_t, libc:: // According to the POSIX specification, -1 is used to indicate that owner and group // are not to be changed. Since uid_t and gid_t are unsigned types, we have to wrap // around to get -1. - let uid = owner.map(Into::into).unwrap_or((0 as uid_t).wrapping_sub(1)); - let gid = group.map(Into::into).unwrap_or((0 as gid_t).wrapping_sub(1)); + let uid = owner.map(Into::into) + .unwrap_or_else(|| (0 as uid_t).wrapping_sub(1)); + let gid = group.map(Into::into) + .unwrap_or_else(|| (0 as gid_t).wrapping_sub(1)); (uid, gid) } @@ -1199,7 +1201,7 @@ pub fn chroot<P: ?Sized + NixPath>(path: &P) -> Result<()> { target_os = "netbsd", target_os = "openbsd" ))] -pub fn sync() -> () { +pub fn sync() { unsafe { libc::sync() }; } |