diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-30 16:52:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-30 16:52:04 +0000 |
commit | a4a465d25567f163f9552b977eb4d17435251d41 (patch) | |
tree | fc1b314ffbaef34fd3b9acab510a0071fb5d31c3 /src/sys | |
parent | faaacf959a47f286306ae73a2b24a649e2249199 (diff) | |
parent | 1c267caf2f9784db47dffc764c5b71b8e918e567 (diff) | |
download | nix-a4a465d25567f163f9552b977eb4d17435251d41.zip |
Merge #1107
1107: Clippy cleanup r=asomers a=asomers
This is preparation for several changes relating to raising the MSRV, most importantly eliminating `mem::uninitialized`.
Co-authored-by: Alan Somers <asomers@gmail.com>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/aio.rs | 1 | ||||
-rw-r--r-- | src/sys/event.rs | 2 | ||||
-rw-r--r-- | src/sys/select.rs | 6 | ||||
-rw-r--r-- | src/sys/sendfile.rs | 4 | ||||
-rw-r--r-- | src/sys/signal.rs | 4 | ||||
-rw-r--r-- | src/sys/socket/addr.rs | 109 | ||||
-rw-r--r-- | src/sys/socket/mod.rs | 82 | ||||
-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 |
10 files changed, 133 insertions, 87 deletions
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/select.rs b/src/sys/select.rs index 1b518e29..9d60ffaf 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -69,6 +69,12 @@ impl FdSet { } } +impl Default for FdSet { + fn default() -> Self { + Self::new() + } +} + /// Monitors file descriptors for readiness /// /// Returns the total number of ready file descriptors in all sets. The sets are changed so that all 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..cbec71f7 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)))), @@ -761,26 +768,54 @@ impl SockAddr { /// a sockaddr * need to take the size of the underlying type as well and then internally cast it back. pub unsafe fn as_ffi_pair(&self) -> (&libc::sockaddr, libc::socklen_t) { match *self { - SockAddr::Inet(InetAddr::V4(ref addr)) => (mem::transmute(addr), mem::size_of::<libc::sockaddr_in>() as libc::socklen_t), - SockAddr::Inet(InetAddr::V6(ref addr)) => (mem::transmute(addr), mem::size_of::<libc::sockaddr_in6>() as libc::socklen_t), - SockAddr::Unix(UnixAddr(ref addr, len)) => (mem::transmute(addr), (len + offset_of!(libc::sockaddr_un, sun_path)) as libc::socklen_t), + SockAddr::Inet(InetAddr::V4(ref addr)) => ( + &*(addr as *const libc::sockaddr_in as *const libc::sockaddr), + mem::size_of_val(addr) as libc::socklen_t + ), + SockAddr::Inet(InetAddr::V6(ref addr)) => ( + &*(addr as *const libc::sockaddr_in6 as *const libc::sockaddr), + mem::size_of_val(addr) as libc::socklen_t + ), + SockAddr::Unix(UnixAddr(ref addr, len)) => ( + &*(addr as *const libc::sockaddr_un as *const libc::sockaddr), + (len + offset_of!(libc::sockaddr_un, sun_path)) as libc::socklen_t + ), #[cfg(any(target_os = "android", target_os = "linux"))] - SockAddr::Netlink(NetlinkAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_nl>() as libc::socklen_t), + SockAddr::Netlink(NetlinkAddr(ref sa)) => ( + &*(sa as *const libc::sockaddr_nl as *const libc::sockaddr), + mem::size_of_val(sa) as libc::socklen_t + ), #[cfg(any(target_os = "android", target_os = "linux"))] - SockAddr::Alg(AlgAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_alg>() as libc::socklen_t), + SockAddr::Alg(AlgAddr(ref sa)) => ( + &*(sa as *const libc::sockaddr_alg as *const libc::sockaddr), + mem::size_of_val(sa) as libc::socklen_t + ), #[cfg(any(target_os = "ios", target_os = "macos"))] - SockAddr::SysControl(SysControlAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_ctl>() as libc::socklen_t), + SockAddr::SysControl(SysControlAddr(ref sa)) => ( + &*(sa as *const libc::sockaddr_ctl as *const libc::sockaddr), + mem::size_of_val(sa) as libc::socklen_t + + ), #[cfg(any(target_os = "android", target_os = "linux"))] - SockAddr::Link(LinkAddr(ref ether_addr)) => (mem::transmute(ether_addr), mem::size_of::<libc::sockaddr_ll>() as libc::socklen_t), + SockAddr::Link(LinkAddr(ref addr)) => ( + &*(addr as *const libc::sockaddr_ll as *const libc::sockaddr), + mem::size_of_val(addr) as libc::socklen_t + ), #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd"))] - SockAddr::Link(LinkAddr(ref ether_addr)) => (mem::transmute(ether_addr), mem::size_of::<libc::sockaddr_dl>() as libc::socklen_t), + SockAddr::Link(LinkAddr(ref addr)) => ( + &*(addr as *const libc::sockaddr_dl as *const libc::sockaddr), + mem::size_of_val(addr) as libc::socklen_t + ), #[cfg(target_os = "linux")] - SockAddr::Vsock(VsockAddr(ref sa)) => (mem::transmute(sa), mem::size_of::<libc::sockaddr_vm>() as libc::socklen_t), + SockAddr::Vsock(VsockAddr(ref sa)) => ( + &*(sa as *const libc::sockaddr_vm as *const libc::sockaddr), + mem::size_of_val(sa) as libc::socklen_t + ), } } } @@ -957,7 +992,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 +1058,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 +1104,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 +1140,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 +1150,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..662d8803 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -344,6 +344,8 @@ impl<T> CmsgSpace<T> { /// Create a CmsgSpace<T>. The structure is used only for space, so /// the fields are uninitialized. #[deprecated( since="0.14.0", note="Use the cmsg_space! macro instead")] + // It's deprecated anyway; no sense adding Default + #[allow(clippy::new_without_default)] pub fn new() -> Self { // Safe because the fields themselves aren't accessible. unsafe { mem::uninitialized() } @@ -540,9 +542,9 @@ impl ControlMessageOwned { /// specified in the header. Normally, the kernel ensures that this is the /// case. "Correct" in this case includes correct length, alignment and /// actual content. - /// - /// Returns `None` if the data may be unaligned. In that case use - /// `ControlMessageOwned::decode_from`. + // Clippy complains about the pointer alignment of `p`, not understanding + // that it's being fed to a function that can handle that. + #[allow(clippy::cast_ptr_alignment)] unsafe fn decode_from(header: &cmsghdr) -> ControlMessageOwned { let p = CMSG_DATA(header); @@ -553,11 +555,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 +716,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 +738,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 +757,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 +782,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 }, } @@ -1076,7 +1076,7 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result<usize> { /// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html) pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> { unsafe { - let addr: sockaddr_storage = mem::zeroed(); + let mut addr: sockaddr_storage = mem::zeroed(); let mut len = mem::size_of::<sockaddr_storage>() as socklen_t; let ret = Errno::result(libc::recvfrom( @@ -1084,7 +1084,7 @@ pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> { buf.as_ptr() as *mut c_void, buf.len() as size_t, 0, - mem::transmute(&addr), + &mut addr as *mut libc::sockaddr_storage as *mut libc::sockaddr, &mut len as *mut socklen_t))?; sockaddr_storage_to_addr(&addr, len as usize) @@ -1190,10 +1190,14 @@ pub fn setsockopt<O: SetSockOpt>(fd: RawFd, opt: O, val: &O::Val) -> Result<()> /// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html) pub fn getpeername(fd: RawFd) -> Result<SockAddr> { unsafe { - let addr: sockaddr_storage = mem::uninitialized(); + let mut addr: sockaddr_storage = mem::uninitialized(); let mut len = mem::size_of::<sockaddr_storage>() as socklen_t; - let ret = libc::getpeername(fd, mem::transmute(&addr), &mut len); + let ret = libc::getpeername( + fd, + &mut addr as *mut libc::sockaddr_storage as *mut libc::sockaddr, + &mut len + ); Errno::result(ret)?; @@ -1206,10 +1210,14 @@ pub fn getpeername(fd: RawFd) -> Result<SockAddr> { /// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html) pub fn getsockname(fd: RawFd) -> Result<SockAddr> { unsafe { - let addr: sockaddr_storage = mem::uninitialized(); + let mut addr: sockaddr_storage = mem::uninitialized(); let mut len = mem::size_of::<sockaddr_storage>() as socklen_t; - let ret = libc::getsockname(fd, mem::transmute(&addr), &mut len); + let ret = libc::getsockname( + fd, + &mut addr as *mut libc::sockaddr_storage as *mut libc::sockaddr, + &mut len + ); Errno::result(ret)?; @@ -1231,7 +1239,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, ) |