diff --git a/Cargo.toml b/Cargo.toml index 1c3dca4..3af5adc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ unit_bindings = "warn" unused_import_braces = "warn" unused_lifetimes = "warn" unused_macro_rules = "warn" -# unused_qualifications = "warn" // Try to re-enable when MSRV is > 1.76 +# unused_qualifications = "warn" # Try to re-enable when MSRV is > 1.76 [lints.clippy] cargo = { level = "warn", priority = -1 } diff --git a/src/bsd.rs b/src/bsd.rs index d6ced67..4fffa93 100644 --- a/src/bsd.rs +++ b/src/bsd.rs @@ -42,7 +42,7 @@ use crate::{ }; #[cfg(apple)] -const ALIGN: usize = std::mem::size_of::(); +const ALIGN: usize = size_of::(); #[cfg(bsd)] // See https://github.com/freebsd/freebsd-src/blob/524a425d30fce3d5e47614db796046830b1f6a83/sys/net/route.h#L362-L371 @@ -65,12 +65,12 @@ type AddressFamily = u16; asserted_const_with_type!(AF_INET, AddressFamily, libc::AF_INET, i32); asserted_const_with_type!(AF_INET6, AddressFamily, libc::AF_INET6, i32); asserted_const_with_type!(AF_LINK, AddressFamily, libc::AF_LINK, i32); -asserted_const_with_type!(RTM_VERSION, u8, crate::bsd::bindings::RTM_VERSION, u32); -asserted_const_with_type!(RTM_GET, u8, crate::bsd::bindings::RTM_GET, u32); +asserted_const_with_type!(RTM_VERSION, u8, bindings::RTM_VERSION, u32); +asserted_const_with_type!(RTM_GET, u8, bindings::RTM_GET, u32); -const_assert!(std::mem::size_of::() + ALIGN <= u8::MAX as usize); -const_assert!(std::mem::size_of::() + ALIGN <= u8::MAX as usize); -const_assert!(std::mem::size_of::() <= u8::MAX as usize); +const_assert!(size_of::() + ALIGN <= u8::MAX as usize); +const_assert!(size_of::() + ALIGN <= u8::MAX as usize); +const_assert!(size_of::() <= u8::MAX as usize); struct IfAddrs(*mut ifaddrs); @@ -116,7 +116,7 @@ struct IfAddrPtr<'a> { } impl IfAddrPtr<'_> { - fn addr(&self) -> libc::sockaddr { + fn addr(&self) -> sockaddr { unsafe { *self.ifa_addr } } @@ -183,8 +183,8 @@ union SockaddrStorage { fn sockaddr_len(af: AddressFamily) -> Result { let sa_len = match af { - AF_INET => std::mem::size_of::(), - AF_INET6 => std::mem::size_of::(), + AF_INET => size_of::(), + AF_INET6 => size_of::(), _ => { return Err(Error::new( ErrorKind::InvalidInput, @@ -203,7 +203,7 @@ impl From for SockaddrStorage { #[cfg(not(target_os = "solaris"))] #[allow(clippy::cast_possible_truncation)] // `sockaddr_in` len is <= u8::MAX per `const_assert!` above. - sin_len: std::mem::size_of::() as u8, + sin_len: size_of::() as u8, sin_family: AF_INET, sin_addr: in_addr { s_addr: u32::from_ne_bytes(ip.octets()), @@ -217,7 +217,7 @@ impl From for SockaddrStorage { #[cfg(not(target_os = "solaris"))] #[allow(clippy::cast_possible_truncation)] // `sockaddr_in6` len is <= u8::MAX per `const_assert!` above. - sin6_len: std::mem::size_of::() as u8, + sin6_len: size_of::() as u8, sin6_family: AF_INET6, sin6_addr: in6_addr { s6_addr: ip.octets(), @@ -250,7 +250,7 @@ impl RouteMessage { rtm: rt_msghdr { #[allow(clippy::cast_possible_truncation)] // `rt_msghdr` len + `ALIGN` is <= u8::MAX per `const_assert!` above. - rtm_msglen: (std::mem::size_of::() + sa_len) as u16, + rtm_msglen: (size_of::() + sa_len) as u16, rtm_version: RTM_VERSION, rtm_type: RTM_GET, rtm_seq: seq, @@ -276,14 +276,14 @@ impl RouteMessage { impl From<&RouteMessage> for &[u8] { fn from(value: &RouteMessage) -> Self { - debug_assert!(value.len() >= std::mem::size_of::()); + debug_assert!(value.len() >= size_of::()); unsafe { slice::from_raw_parts(ptr::from_ref(value).cast(), value.len()) } } } impl From<&[u8]> for rt_msghdr { fn from(value: &[u8]) -> Self { - debug_assert!(value.len() >= std::mem::size_of::()); + debug_assert!(value.len() >= size_of::()); unsafe { ptr::read_unaligned(value.as_ptr().cast()) } } } @@ -304,15 +304,15 @@ fn if_index_mtu(remote: IpAddr) -> Result<(u16, Option)> { loop { let mut buf = vec![ 0u8; - std::mem::size_of::() + + size_of::() + // There will never be `RTAX_MAX` sockaddrs attached, but it's a safe upper bound. - (RTAX_MAX as usize * std::mem::size_of::()) + (RTAX_MAX as usize * size_of::()) ]; let len = fd.read(&mut buf[..])?; - if len < std::mem::size_of::() { + if len < size_of::() { return Err(default_err()); } - let (reply, mut sa) = buf.split_at(std::mem::size_of::()); + let (reply, mut sa) = buf.split_at(size_of::()); let reply: rt_msghdr = reply.into(); if !(reply.rtm_version == query_version && reply.rtm_pid == pid diff --git a/src/routesocket.rs b/src/routesocket.rs index bfaea45..6416c55 100644 --- a/src/routesocket.rs +++ b/src/routesocket.rs @@ -60,19 +60,19 @@ fn check_result(res: isize) -> Result { } impl Write for RouteSocket { - fn write(&mut self, buf: &[u8]) -> std::io::Result { + fn write(&mut self, buf: &[u8]) -> Result { let res = unsafe { write(self.as_raw_fd(), buf.as_ptr().cast(), buf.len()) }; check_result(res) } - fn flush(&mut self) -> std::io::Result<()> { + fn flush(&mut self) -> Result<()> { let res = unsafe { fsync(self.as_raw_fd()) }; check_result(res as isize).and(Ok(())) } } impl Read for RouteSocket { - fn read(&mut self, buf: &mut [u8]) -> std::io::Result { + fn read(&mut self, buf: &mut [u8]) -> Result { // If we've written a well-formed message into the kernel via `write`, we should be able to // read a well-formed message back out, and not block. let res = unsafe { read(self.as_raw_fd(), buf.as_mut_ptr().cast(), buf.len()) };