Skip to content

Commit

Permalink
Merge branch 'clippy-upkeep' into new_async_io_interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Nov 30, 2023
2 parents 587fef4 + 86849c2 commit a223023
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
27 changes: 17 additions & 10 deletions src/stdnet/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }

fn last_err() -> io::Result<Option<usize>> {
let err = unsafe { WSAGetLastError() };
if err == WSA_IO_PENDING as i32 {
if err == WSA_IO_PENDING {
Ok(None)
} else {
Err(io::Error::from_raw_os_error(err))
Expand Down Expand Up @@ -317,14 +317,14 @@ unsafe fn ptrs_to_socket_addr(ptr: *const SOCKADDR, len: c_int) -> Option<Socket
c::AF_UNIX if len as usize >= mem::size_of::<c::sockaddr_un>() => {
let b = &*(ptr as *const c::sockaddr_un);
match b.sun_path.iter().position(|c| *c == 0) {
Some(0) => from_sockaddr_un(b.clone(), len).ok(),
Some(0) => from_sockaddr_un(*b, len).ok(),
Some(i) => {
let mut l = sun_path_offset(b) + i;
match b.sun_path.get(0) {
match b.sun_path.first() {
Some(&0) | None => {}
Some(_) => l += 1,
}
from_sockaddr_un(b.clone(), l as c_int).ok()
from_sockaddr_un(*b, l as c_int).ok()
}
_ => None, // Invalid socket path, no terminating null byte
}
Expand Down Expand Up @@ -424,7 +424,7 @@ impl UnixStreamExt for UnixStream {
self.as_raw_socket() as SOCKET,
SOL_SOCKET,
SO_UPDATE_CONNECT_CONTEXT,
0 as *const _,
std::ptr::null(),
0,
)
};
Expand Down Expand Up @@ -594,6 +594,12 @@ type GetAcceptExSockaddrs = unsafe extern "system" fn(
LPINT,
);

impl Default for AcceptAddrsBuf {
fn default() -> Self {
Self::new()
}
}

impl AcceptAddrsBuf {
/// Creates a new blank buffer ready to be passed to a call to
/// `accept_overlapped`.
Expand All @@ -608,9 +614,9 @@ impl AcceptAddrsBuf {
/// succeeded to parse out the data that was written in.
pub fn parse(&self, socket: &UnixListener) -> io::Result<AcceptAddrs> {
let mut ret = AcceptAddrs {
local: 0 as *mut _,
local: std::ptr::null_mut(),
local_len: 0,
remote: 0 as *mut _,
remote: std::ptr::null_mut(),
remote_len: 0,
_data: self,
};
Expand All @@ -634,7 +640,8 @@ impl AcceptAddrsBuf {
}

fn args(&self) -> (PVOID, DWORD, DWORD, DWORD) {
let remote_offset = unsafe { &(*(0 as *const AcceptAddrsBuf)).remote as *const _ as usize };
let remote_offset =
unsafe { &(*std::ptr::null::<AcceptAddrsBuf>()).remote as *const _ as usize };
(
self as *const _ as *mut _,
0,
Expand Down Expand Up @@ -663,7 +670,7 @@ impl WsaExtension {
if prev != 0 && !cfg!(debug_assertions) {
return Ok(prev);
}
let mut ret = 0 as usize;
let mut ret = 0_usize;
let mut bytes = 0;
let r = unsafe {
WSAIoctl(
Expand All @@ -674,7 +681,7 @@ impl WsaExtension {
&mut ret as *mut _ as *mut _,
mem::size_of_val(&ret) as DWORD,
&mut bytes,
0 as *mut _,
std::ptr::null_mut(),
None,
)
};
Expand Down
11 changes: 3 additions & 8 deletions src/stdnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub unsafe fn sockaddr_un(path: &Path) -> io::Result<(c::sockaddr_un, c_int)> {
// struct

let mut len = sun_path_offset(&addr) + bytes.len();
match bytes.get(0) {
match bytes.first() {
Some(&0) | None => {}
Some(_) => len += 1,
}
Expand Down Expand Up @@ -191,11 +191,7 @@ impl SocketAddr {
// assert_eq!(addr.is_unnamed(), true);
// ```
pub fn is_unnamed(&self) -> bool {
if let AddressKind::Unnamed = self.address() {
true
} else {
false
}
matches!(self.address(), AddressKind::Unnamed)
}

/// Returns the contents of this address if it is a `pathname` address.
Expand Down Expand Up @@ -232,7 +228,7 @@ impl SocketAddr {
}
}

fn address<'a>(&'a self) -> AddressKind<'a> {
fn address(&self) -> AddressKind {
let len = self.len as usize - sun_path_offset(&self.addr);
// sockaddr_un::sun_path on Windows is a Win32 UTF-8 file system path
let path = unsafe { mem::transmute::<&[c_char], &[u8]>(&self.addr.sun_path) };
Expand Down Expand Up @@ -297,4 +293,3 @@ impl<'a> fmt::Display for AsciiEscaped<'a> {

pub use self::ext::{AcceptAddrs, AcceptAddrsBuf, UnixListenerExt, UnixStreamExt};
pub use self::net::{UnixListener, UnixStream};
pub use self::socket::{init, Socket};
6 changes: 3 additions & 3 deletions src/stdnet/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl UnixStream {
cvt(connect(
inner.as_raw_socket() as _,
&addr as *const _ as *const _,
len as i32,
len,
))?;
Ok(UnixStream(inner))
}
Expand Down Expand Up @@ -198,7 +198,7 @@ impl UnixStream {
.join()
.map_err(|_| io::Error::from(io::ErrorKind::ConnectionRefused))?;
let stream0 = (*(a.write().unwrap())).take().unwrap()?;
return Ok((stream0, stream1));
Ok((stream0, stream1))
}

/// Sets the read timeout to the timeout specified.
Expand Down Expand Up @@ -528,7 +528,7 @@ impl UnixListener {
/// }
/// }
/// ```
pub fn incoming<'a>(&'a self) -> Incoming<'a> {
pub fn incoming(&self) -> Incoming<'_> {
Incoming { listener: self }
}
}
Expand Down

0 comments on commit a223023

Please sign in to comment.