From a09b1c8ac643d448db479a108ac6726307075453 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 18 Sep 2021 21:07:00 -0600 Subject: Clippy cleanup And this time, start running Clippy in CI --- src/sys/socket/addr.rs | 16 +++++++++------- src/sys/socket/mod.rs | 11 ++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/sys/socket') diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 38dd4190..832a153f 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1,5 +1,5 @@ use super::sa_family_t; -use crate::{Error, Result, NixPath}; +use crate::{Result, NixPath}; use crate::errno::Errno; use memoffset::offset_of; use std::{fmt, mem, net, ptr, slice}; @@ -270,6 +270,7 @@ pub enum InetAddr { } impl InetAddr { + #[allow(clippy::needless_update)] // It isn't needless on all OSes pub fn from_std(std: &net::SocketAddr) -> InetAddr { match *std { net::SocketAddr::V4(ref addr) => { @@ -293,6 +294,7 @@ impl InetAddr { } } + #[allow(clippy::needless_update)] // It isn't needless on all OSes pub fn new(ip: IpAddr, port: u16) -> InetAddr { match ip { IpAddr::V4(ref ip) => { @@ -565,7 +567,7 @@ impl UnixAddr { let bytes = cstr.to_bytes(); if bytes.len() >= ret.sun_path.len() { - return Err(Error::from(Errno::ENAMETOOLONG)); + return Err(Errno::ENAMETOOLONG); } ptr::copy_nonoverlapping(bytes.as_ptr(), @@ -592,7 +594,7 @@ impl UnixAddr { }; if path.len() >= ret.sun_path.len() { - return Err(Error::from(Errno::ENAMETOOLONG)); + return Err(Errno::ENAMETOOLONG); } // Abstract addresses are represented by sun_path[0] == @@ -751,7 +753,7 @@ impl SockAddr { #[cfg(any(target_os = "ios", target_os = "macos"))] pub fn new_sys_control(sockfd: RawFd, name: &str, unit: u32) -> Result { - SysControlAddr::from_name(sockfd, name, unit).map(|a| SockAddr::SysControl(a)) + SysControlAddr::from_name(sockfd, name, unit).map(SockAddr::SysControl) } #[cfg(any(target_os = "android", target_os = "linux"))] @@ -1064,7 +1066,7 @@ pub mod sys_control { use libc::{self, c_uchar}; use std::{fmt, mem}; use std::os::unix::io::RawFd; - use crate::{Errno, Error, Result}; + use crate::{Errno, Result}; // FIXME: Move type into `libc` #[repr(C)] @@ -1075,7 +1077,7 @@ pub mod sys_control { pub ctl_name: [c_uchar; MAX_KCTL_NAME], } - const CTL_IOC_MAGIC: u8 = 'N' as u8; + const CTL_IOC_MAGIC: u8 = b'N'; const CTL_IOC_INFO: u8 = 3; const MAX_KCTL_NAME: usize = 96; @@ -1101,7 +1103,7 @@ pub mod sys_control { pub fn from_name(sockfd: RawFd, name: &str, unit: u32) -> Result { if name.len() > MAX_KCTL_NAME { - return Err(Error::from(Errno::ENAMETOOLONG)); + return Err(Errno::ENAMETOOLONG); } let mut ctl_name = [0; MAX_KCTL_NAME]; diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 96328842..97eea3dc 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -2,7 +2,7 @@ //! //! [Further reading](https://man7.org/linux/man-pages/man7/socket.7.html) use cfg_if::cfg_if; -use crate::{Error, Result, errno::Errno}; +use crate::{Result, errno::Errno}; use libc::{self, c_void, c_int, iovec, socklen_t, size_t, CMSG_FIRSTHDR, CMSG_NXTHDR, CMSG_DATA, CMSG_LEN}; use memoffset::offset_of; @@ -311,9 +311,9 @@ cfg_if! { } } - impl Into for UnixCredentials { - fn into(self) -> libc::ucred { - self.0 + impl From for libc::ucred { + fn from(uc: UnixCredentials) -> Self { + uc.0 } } } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { @@ -1300,6 +1300,7 @@ pub struct RecvMmsgData<'a, I> target_os = "freebsd", target_os = "netbsd", ))] +#[allow(clippy::needless_collect)] // Complicated false positive pub fn recvmmsg<'a, I>( fd: RawFd, data: impl std::iter::IntoIterator, @@ -1813,7 +1814,7 @@ pub fn sockaddr_storage_to_addr( assert!(len <= mem::size_of::()); if len < mem::size_of_val(&addr.ss_family) { - return Err(Error::from(Errno::ENOTCONN)); + return Err(Errno::ENOTCONN); } match c_int::from(addr.ss_family) { -- cgit v1.2.3