Skip to content

Commit 8a027c3

Browse files
authored
Miscellaneous clippy fixes. (#1331)
1 parent 77f1ae2 commit 8a027c3

31 files changed

Lines changed: 123 additions & 143 deletions

File tree

src/backend/libc/event/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,6 @@ pub(crate) fn epoll_wait(
589589
events.len().try_into().unwrap_or(i32::MAX),
590590
timeout,
591591
))
592-
.map(|i| i.try_into().unwrap_or(usize::MAX))
592+
.map(|i| i as usize)
593593
}
594594
}

src/backend/libc/fs/syscalls.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,6 @@ pub(crate) fn sendfile(
18311831

18321832
/// Convert from a Linux `statx` value to rustix's `Stat`.
18331833
#[cfg(all(linux_kernel, target_pointer_width = "32"))]
1834-
#[allow(deprecated)] // for `st_[amc]time` u64->i64 transition
18351834
fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
18361835
Ok(Stat {
18371836
st_dev: crate::fs::makedev(x.stx_dev_major, x.stx_dev_minor).into(),
@@ -1882,7 +1881,6 @@ fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
18821881

18831882
/// Convert from a Linux `stat64` value to rustix's `Stat`.
18841883
#[cfg(all(linux_kernel, target_pointer_width = "32"))]
1885-
#[allow(deprecated)] // for `st_[amc]time` u64->i64 transition
18861884
fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
18871885
Ok(Stat {
18881886
st_dev: s64.st_dev.try_into().map_err(|_| io::Errno::OVERFLOW)?,

src/backend/libc/net/addr.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
use crate::backend::c;
44
use crate::net::AddressFamily;
5-
use core::mem::size_of;
6-
use core::slice;
75
#[cfg(unix)]
86
use {
97
crate::ffi::CStr,
@@ -13,6 +11,7 @@ use {
1311
core::cmp::Ordering,
1412
core::fmt,
1513
core::hash::{Hash, Hasher},
14+
core::slice,
1615
};
1716

1817
/// `struct sockaddr_un`
@@ -272,16 +271,6 @@ impl SocketAddrStorage {
272271
)
273272
}
274273
}
275-
276-
/// View the storage as a byte slice.
277-
pub fn as_mut_bytes(&mut self) -> &mut [u8] {
278-
unsafe {
279-
slice::from_raw_parts_mut(
280-
crate::utils::as_mut_ptr(self).cast::<u8>(),
281-
size_of::<Self>(),
282-
)
283-
}
284-
}
285274
}
286275

287276
/// Return the offset of the `sun_path` field of `sockaddr_un`.

src/backend/libc/net/sockopt.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ use windows_sys::Win32::Foundation::BOOL;
8282

8383
#[inline]
8484
fn getsockopt<T: Copy>(fd: BorrowedFd<'_>, level: i32, optname: i32) -> io::Result<T> {
85-
let mut optlen = core::mem::size_of::<T>().try_into().unwrap();
85+
let mut optlen = size_of::<T>().try_into().unwrap();
8686
debug_assert!(
87-
optlen as usize >= core::mem::size_of::<c::c_int>(),
87+
optlen as usize >= size_of::<c::c_int>(),
8888
"Socket APIs don't ever use `bool` directly"
8989
);
9090

@@ -125,9 +125,9 @@ fn getsockopt_raw<T>(
125125

126126
#[inline]
127127
fn setsockopt<T: Copy>(fd: BorrowedFd<'_>, level: i32, optname: i32, value: T) -> io::Result<()> {
128-
let optlen = core::mem::size_of::<T>().try_into().unwrap();
128+
let optlen = size_of::<T>().try_into().unwrap();
129129
debug_assert!(
130-
optlen as usize >= core::mem::size_of::<c::c_int>(),
130+
optlen as usize >= size_of::<c::c_int>(),
131131
"Socket APIs don't ever use `bool` directly"
132132
);
133133
setsockopt_raw(fd, level, optname, &value, optlen)
@@ -1077,15 +1077,15 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
10771077
// kernel version. This works because C will layout all struct members one
10781078
// after the other.
10791079

1080-
let mut optlen = core::mem::size_of::<xdp_mmap_offsets>().try_into().unwrap();
1080+
let mut optlen = size_of::<xdp_mmap_offsets>().try_into().unwrap();
10811081
debug_assert!(
1082-
optlen as usize >= core::mem::size_of::<c::c_int>(),
1082+
optlen as usize >= size_of::<c::c_int>(),
10831083
"Socket APIs don't ever use `bool` directly"
10841084
);
10851085
let mut value = MaybeUninit::<xdp_mmap_offsets>::zeroed();
10861086
getsockopt_raw(fd, c::SOL_XDP, c::XDP_MMAP_OFFSETS, &mut value, &mut optlen)?;
10871087

1088-
if optlen as usize == core::mem::size_of::<c::xdp_mmap_offsets_v1>() {
1088+
if optlen as usize == size_of::<c::xdp_mmap_offsets_v1>() {
10891089
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
10901090
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
10911091
let xpd_mmap_offsets = unsafe { value.assume_init() };
@@ -1118,7 +1118,7 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
11181118
} else {
11191119
assert_eq!(
11201120
optlen as usize,
1121-
core::mem::size_of::<xdp_mmap_offsets>(),
1121+
size_of::<xdp_mmap_offsets>(),
11221122
"unexpected getsockopt size"
11231123
);
11241124
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
@@ -1156,15 +1156,15 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
11561156
#[cfg(target_os = "linux")]
11571157
#[inline]
11581158
pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
1159-
let mut optlen = core::mem::size_of::<xdp_statistics>().try_into().unwrap();
1159+
let mut optlen = size_of::<xdp_statistics>().try_into().unwrap();
11601160
debug_assert!(
1161-
optlen as usize >= core::mem::size_of::<c::c_int>(),
1161+
optlen as usize >= size_of::<c::c_int>(),
11621162
"Socket APIs don't ever use `bool` directly"
11631163
);
11641164
let mut value = MaybeUninit::<xdp_statistics>::zeroed();
11651165
getsockopt_raw(fd, c::SOL_XDP, c::XDP_STATISTICS, &mut value, &mut optlen)?;
11661166

1167-
if optlen as usize == core::mem::size_of::<xdp_statistics_v1>() {
1167+
if optlen as usize == size_of::<xdp_statistics_v1>() {
11681168
// Safety: All members of xdp_statistics are u64 and thus are correctly
11691169
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
11701170
let xdp_statistics = unsafe { value.assume_init() };
@@ -1179,7 +1179,7 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
11791179
} else {
11801180
assert_eq!(
11811181
optlen as usize,
1182-
core::mem::size_of::<xdp_statistics>(),
1182+
size_of::<xdp_statistics>(),
11831183
"unexpected getsockopt size"
11841184
);
11851185
// Safety: All members of xdp_statistics are u64 and thus are correctly

src/backend/libc/pipe/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a> IoSliceRaw<'a> {
8181
pub fn from_slice(buf: &'a [u8]) -> Self {
8282
IoSliceRaw {
8383
_buf: c::iovec {
84-
iov_base: buf.as_ptr() as *mut u8 as *mut c::c_void,
84+
iov_base: (buf.as_ptr() as *mut u8).cast::<c::c_void>(),
8585
iov_len: buf.len() as _,
8686
},
8787
_lifetime: PhantomData,
@@ -92,7 +92,7 @@ impl<'a> IoSliceRaw<'a> {
9292
pub fn from_slice_mut(buf: &'a mut [u8]) -> Self {
9393
IoSliceRaw {
9494
_buf: c::iovec {
95-
iov_base: buf.as_mut_ptr() as *mut c::c_void,
95+
iov_base: buf.as_mut_ptr().cast::<c::c_void>(),
9696
iov_len: buf.len() as _,
9797
},
9898
_lifetime: PhantomData,

src/backend/libc/pty/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(crate) fn ptsname(fd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CSt
8585
match c::ioctl(borrowed_fd(fd), c::TIOCPTYGNAME as _, &mut name) {
8686
0 => {
8787
let len = CStr::from_ptr(name.as_ptr().cast()).to_bytes().len();
88-
std::ptr::copy_nonoverlapping(name.as_ptr(), buffer.as_mut_ptr(), len + 1);
88+
core::ptr::copy_nonoverlapping(name.as_ptr(), buffer.as_mut_ptr(), len + 1);
8989
0
9090
}
9191
_ => libc_errno::errno().0,

src/backend/linux_raw/fs/syscalls.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,6 @@ fn lstat_old(path: &CStr) -> io::Result<Stat> {
718718
target_arch = "mips64",
719719
target_arch = "mips64r6"
720720
))]
721-
#[allow(deprecated)] // for `st_[amc]time` u64->i64 transition
722721
fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
723722
Ok(Stat {
724723
st_dev: crate::fs::makedev(x.stx_dev_major, x.stx_dev_minor),
@@ -742,7 +741,6 @@ fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
742741

743742
/// Convert from a Linux `stat64` value to rustix's `Stat`.
744743
#[cfg(target_pointer_width = "32")]
745-
#[allow(deprecated)] // for `st_[amc]time` u64->i64 transition
746744
fn stat_to_stat(s64: linux_raw_sys::general::stat64) -> io::Result<Stat> {
747745
Ok(Stat {
748746
st_dev: s64.st_dev.try_into().map_err(|_| io::Errno::OVERFLOW)?,
@@ -945,7 +943,7 @@ fn statfs_to_statvfs(statfs: StatFs) -> StatVfs {
945943
f_files: statfs.f_files as u64,
946944
f_ffree: statfs.f_ffree as u64,
947945
f_favail: statfs.f_ffree as u64,
948-
f_fsid: u64::from(f_fsid_val0 as u32) | u64::from(f_fsid_val1 as u32) << 32,
946+
f_fsid: u64::from(f_fsid_val0 as u32) | (u64::from(f_fsid_val1 as u32) << 32),
949947
f_flag: StatVfsMountFlags::from_bits_retain(statfs.f_flags as u64),
950948
f_namemax: statfs.f_namelen as u64,
951949
}

src/backend/linux_raw/net/addr.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::net::AddressFamily;
1313
use crate::{io, path};
1414
use core::cmp::Ordering;
1515
use core::hash::{Hash, Hasher};
16-
use core::mem::size_of;
1716
use core::{fmt, slice};
1817

1918
/// `struct sockaddr_un`
@@ -76,12 +75,10 @@ impl SocketAddrUnix {
7675
/// - [Linux]
7776
///
7877
/// [Linux]: https://www.man7.org/linux/man-pages/man7/unix.7.html
79-
#[cfg(linux_kernel)]
8078
#[inline]
8179
pub fn new_unnamed() -> Self {
8280
Self {
8381
unix: Self::init(),
84-
#[cfg(not(any(bsd, target_os = "haiku")))]
8582
len: offsetof_sun_path() as SocketAddrLen,
8683
}
8784
}
@@ -116,7 +113,6 @@ impl SocketAddrUnix {
116113
}
117114

118115
/// `true` if the socket address is unnamed.
119-
#[cfg(linux_kernel)]
120116
#[inline]
121117
pub fn is_unnamed(&self) -> bool {
122118
self.bytes() == Some(&[])
@@ -234,16 +230,6 @@ impl SocketAddrStorage {
234230
)
235231
}
236232
}
237-
238-
/// View the storage as a byte slice.
239-
pub fn as_mut_bytes(&mut self) -> &mut [u8] {
240-
unsafe {
241-
slice::from_raw_parts_mut(
242-
crate::utils::as_mut_ptr(self).cast::<u8>(),
243-
size_of::<Self>(),
244-
)
245-
}
246-
}
247233
}
248234

249235
/// Return the offset of the `sun_path` field of `sockaddr_un`.

src/backend/linux_raw/net/sockopt.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::net::{
2222
use alloc::borrow::ToOwned;
2323
#[cfg(feature = "alloc")]
2424
use alloc::string::String;
25-
use core::mem::MaybeUninit;
25+
use core::mem::{size_of, MaybeUninit};
2626
use core::time::Duration;
2727
use linux_raw_sys::general::{__kernel_old_timeval, __kernel_sock_timeval};
2828
use linux_raw_sys::net::{IPV6_MTU, IPV6_MULTICAST_IF, IP_MTU, IP_MULTICAST_IF};
@@ -37,9 +37,9 @@ use {
3737

3838
#[inline]
3939
fn getsockopt<T: Copy>(fd: BorrowedFd<'_>, level: u32, optname: u32) -> io::Result<T> {
40-
let mut optlen: c::socklen_t = core::mem::size_of::<T>().try_into().unwrap();
40+
let mut optlen: c::socklen_t = size_of::<T>().try_into().unwrap();
4141
debug_assert!(
42-
optlen as usize >= core::mem::size_of::<c::c_int>(),
42+
optlen as usize >= size_of::<c::c_int>(),
4343
"Socket APIs don't ever use `bool` directly"
4444
);
4545

@@ -48,7 +48,7 @@ fn getsockopt<T: Copy>(fd: BorrowedFd<'_>, level: u32, optname: u32) -> io::Resu
4848

4949
assert_eq!(
5050
optlen as usize,
51-
core::mem::size_of::<T>(),
51+
size_of::<T>(),
5252
"unexpected getsockopt size"
5353
);
5454

@@ -92,9 +92,9 @@ fn getsockopt_raw<T>(
9292

9393
#[inline]
9494
fn setsockopt<T: Copy>(fd: BorrowedFd<'_>, level: u32, optname: u32, value: T) -> io::Result<()> {
95-
let optlen = core::mem::size_of::<T>().try_into().unwrap();
95+
let optlen = size_of::<T>().try_into().unwrap();
9696
debug_assert!(
97-
optlen as usize >= core::mem::size_of::<c::c_int>(),
97+
optlen as usize >= size_of::<c::c_int>(),
9898
"Socket APIs don't ever use `bool` directly"
9999
);
100100
setsockopt_raw(fd, level, optname, &value, optlen)
@@ -883,15 +883,15 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
883883
// kernel version. This works because C will layout all struct members one
884884
// after the other.
885885

886-
let mut optlen = core::mem::size_of::<xdp_mmap_offsets>().try_into().unwrap();
886+
let mut optlen = size_of::<xdp_mmap_offsets>().try_into().unwrap();
887887
debug_assert!(
888-
optlen as usize >= core::mem::size_of::<c::c_int>(),
888+
optlen as usize >= size_of::<c::c_int>(),
889889
"Socket APIs don't ever use `bool` directly"
890890
);
891891
let mut value = MaybeUninit::<xdp_mmap_offsets>::zeroed();
892892
getsockopt_raw(fd, c::SOL_XDP, c::XDP_MMAP_OFFSETS, &mut value, &mut optlen)?;
893893

894-
if optlen as usize == core::mem::size_of::<c::xdp_mmap_offsets_v1>() {
894+
if optlen as usize == size_of::<c::xdp_mmap_offsets_v1>() {
895895
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
896896
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
897897
let xpd_mmap_offsets = unsafe { value.assume_init() };
@@ -924,7 +924,7 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
924924
} else {
925925
assert_eq!(
926926
optlen as usize,
927-
core::mem::size_of::<xdp_mmap_offsets>(),
927+
size_of::<xdp_mmap_offsets>(),
928928
"unexpected getsockopt size"
929929
);
930930
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
@@ -962,15 +962,15 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
962962
#[cfg(target_os = "linux")]
963963
#[inline]
964964
pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
965-
let mut optlen = core::mem::size_of::<xdp_statistics>().try_into().unwrap();
965+
let mut optlen = size_of::<xdp_statistics>().try_into().unwrap();
966966
debug_assert!(
967-
optlen as usize >= core::mem::size_of::<c::c_int>(),
967+
optlen as usize >= size_of::<c::c_int>(),
968968
"Socket APIs don't ever use `bool` directly"
969969
);
970970
let mut value = MaybeUninit::<xdp_statistics>::zeroed();
971971
getsockopt_raw(fd, c::SOL_XDP, c::XDP_STATISTICS, &mut value, &mut optlen)?;
972972

973-
if optlen as usize == core::mem::size_of::<xdp_statistics_v1>() {
973+
if optlen as usize == size_of::<xdp_statistics_v1>() {
974974
// Safety: All members of xdp_statistics are u64 and thus are correctly
975975
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
976976
let xdp_statistics = unsafe { value.assume_init() };
@@ -985,7 +985,7 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
985985
} else {
986986
assert_eq!(
987987
optlen as usize,
988-
core::mem::size_of::<xdp_statistics>(),
988+
size_of::<xdp_statistics>(),
989989
"unexpected getsockopt size"
990990
);
991991
// Safety: All members of xdp_statistics are u64 and thus are correctly

src/backend/linux_raw/param/auxv.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ use linux_raw_sys::general::{
3232
#[cfg(feature = "alloc")]
3333
use {alloc::borrow::Cow, alloc::vec};
3434

35-
// TODO: Fix linux-raw-sys to define EM_CURRENT for s390x.
36-
#[cfg(target_arch = "s390x")]
37-
const EM_CURRENT: u16 = 22; // EM_S390
38-
3935
#[cfg(feature = "param")]
4036
#[inline]
4137
pub(crate) fn page_size() -> usize {
@@ -248,7 +244,7 @@ fn pr_get_auxv_dynamic(buffer: &mut [u8; 512]) -> crate::io::Result<Cow<'_, [u8]
248244
};
249245

250246
// If that indicates it needs a bigger buffer, allocate one.
251-
let mut buffer = vec![0u8; len];
247+
let mut buffer = vec![0_u8; len];
252248
let len = unsafe {
253249
ret_usize(syscall_always_asm!(
254250
__NR_prctl,
@@ -282,7 +278,7 @@ fn maybe_init_auxv() {
282278
/// /proc/self/auxv for kernels that don't support `PR_GET_AUXV`.
283279
#[cold]
284280
fn init_auxv_impl() -> Result<(), ()> {
285-
let mut buffer = [0u8; 512];
281+
let mut buffer = [0_u8; 512];
286282

287283
// If we don't have "alloc", just try to read into our statically-sized
288284
// buffer. This might fail due to the buffer being insufficient; we're

0 commit comments

Comments
 (0)