From accd840dd29d93d8da81b7a18c4c914f1874ede6 Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Sun, 5 May 2024 12:06:54 +0200 Subject: [PATCH] Update to new lints --- rusl/src/futex.rs | 2 +- rusl/src/platform/compat/io_uring.rs | 2 +- rusl/src/platform/compat/socket.rs | 2 +- rusl/src/select/poll.rs | 4 ++-- rusl/src/string/unix_str.rs | 10 ++++++---- tiny-std/src/allocator/dlmalloc.rs | 1 + tiny-std/src/fs.rs | 2 +- tiny-std/src/io/read_buf.rs | 2 +- tiny-std/src/thread/spawn.rs | 4 ++-- tiny-std/src/unix/passwd/getpw_r.rs | 2 +- 10 files changed, 17 insertions(+), 14 deletions(-) diff --git a/rusl/src/futex.rs b/rusl/src/futex.rs index cb007c7..bdc77e9 100644 --- a/rusl/src/futex.rs +++ b/rusl/src/futex.rs @@ -23,7 +23,7 @@ pub fn futex_wait( val, timeout .as_ref() - .map_or_else(core::ptr::null, |ts| ts as *const TimeSpec), + .map_or_else(core::ptr::null, core::ptr::from_ref::), 0, 0 ) diff --git a/rusl/src/platform/compat/io_uring.rs b/rusl/src/platform/compat/io_uring.rs index 1f90b56..1b1bc24 100644 --- a/rusl/src/platform/compat/io_uring.rs +++ b/rusl/src/platform/compat/io_uring.rs @@ -721,7 +721,7 @@ impl IoUringSubmissionQueueEntry { }, }, __bindgen_anon_2: io_uring_sqe__bindgen_ty_2 { - addr: ts as *const TimeSpec as u64, + addr: core::ptr::from_ref::(ts) as u64, }, len: 1, __bindgen_anon_3: io_uring_sqe__bindgen_ty_3 { diff --git a/rusl/src/platform/compat/socket.rs b/rusl/src/platform/compat/socket.rs index 861331a..bb58ce7 100644 --- a/rusl/src/platform/compat/socket.rs +++ b/rusl/src/platform/compat/socket.rs @@ -641,7 +641,7 @@ mod tests { mut_cm.cmsg_len = cmsg_len; let data = cmsg_data!(cmhdr); core::ptr::copy_nonoverlapping( - fds as *const _ as *const u8, + core::ptr::from_ref(fds) as *const u8, data, core::mem::size_of_val(fds), ); diff --git a/rusl/src/select/poll.rs b/rusl/src/select/poll.rs index 6b8c5ef..12d3884 100644 --- a/rusl/src/select/poll.rs +++ b/rusl/src/select/poll.rs @@ -20,8 +20,8 @@ pub fn ppoll( PPOLL, poll_fds.as_mut_ptr(), poll_fds.len(), - timespec.map_or_else(core::ptr::null, |ts| ts as *const TimeSpec), - sigset.map_or_else(core::ptr::null, |ss_t| ss_t as *const SigSetT) + timespec.map_or_else(core::ptr::null, core::ptr::from_ref::), + sigset.map_or_else(core::ptr::null, core::ptr::from_ref::) ) }; bail_on_below_zero!(res, "`PPOLL` syscall failed"); diff --git a/rusl/src/string/unix_str.rs b/rusl/src/string/unix_str.rs index ce8f99a..e31ce20 100644 --- a/rusl/src/string/unix_str.rs +++ b/rusl/src/string/unix_str.rs @@ -120,7 +120,7 @@ impl core::ops::Deref for UnixString { type Target = UnixStr; fn deref(&self) -> &Self::Target { - unsafe { &*(self.0.as_slice() as *const [u8] as *const UnixStr) } + unsafe { &*(core::ptr::from_ref::<[u8]>(self.0.as_slice()) as *const UnixStr) } } } @@ -183,7 +183,7 @@ impl UnixStr { for (ind, byte) in s.iter().enumerate() { if *byte == NULL_BYTE { return if ind == len - 1 { - unsafe { Ok(&*(s as *const [u8] as *const UnixStr)) } + unsafe { Ok(&*(core::ptr::from_ref::<[u8]>(s) as *const UnixStr)) } } else { Err(Error::no_code("Tried to instantiate UnixStr from an invalid &str, a null byte was found but out of place")) }; @@ -200,7 +200,7 @@ impl UnixStr { pub unsafe fn from_ptr<'a>(s: *const u8) -> &'a Self { let non_null_len = strlen(s); let slice = core::slice::from_raw_parts(s, non_null_len + 1); - &*(slice as *const [u8] as *const Self) + &*(core::ptr::from_ref::<[u8]>(slice) as *const Self) } /// Try to convert this `&UnixStr` to a utf8 `&str` @@ -336,7 +336,9 @@ impl UnixStr { for (ind, byte) in self.0.iter().enumerate().rev() { if *byte == b'/' { return if ind + 2 < self.len() { - unsafe { Some(&*(&self.0[ind + 1..] as *const [u8] as *const Self)) } + unsafe { + Some(&*(core::ptr::from_ref::<[u8]>(&self.0[ind + 1..]) as *const Self)) + } } else { None }; diff --git a/tiny-std/src/allocator/dlmalloc.rs b/tiny-std/src/allocator/dlmalloc.rs index 21140db..283b8e4 100644 --- a/tiny-std/src/allocator/dlmalloc.rs +++ b/tiny-std/src/allocator/dlmalloc.rs @@ -192,6 +192,7 @@ const fn leftshift_for_tree_index(x: u32) -> u32 { } } +#[allow(clippy::new_without_default)] impl Dlmalloc { #[must_use] pub const fn new() -> Dlmalloc { diff --git a/tiny-std/src/fs.rs b/tiny-std/src/fs.rs index 04da4e0..2ebe33c 100644 --- a/tiny-std/src/fs.rs +++ b/tiny-std/src/fs.rs @@ -562,7 +562,7 @@ impl<'a> DirEntry<'a> { // ie. we just did a range check. let tgt = self.inner.d_name.get_unchecked(..=len); // Safety: `&UnixStr` and `&[u8]` have the same layout - Ok(&*(tgt as *const [u8] as *const UnixStr)) + Ok(&*(core::ptr::from_ref::<[u8]>(tgt) as *const UnixStr)) } } diff --git a/tiny-std/src/io/read_buf.rs b/tiny-std/src/io/read_buf.rs index dfc02de..53cfffd 100644 --- a/tiny-std/src/io/read_buf.rs +++ b/tiny-std/src/io/read_buf.rs @@ -167,5 +167,5 @@ pub(crate) unsafe fn slice_assume_init_mut(slice: &mut [MaybeUninit]) -> & // `slice` is initialized, and `MaybeUninit` is guaranteed to have the same layout as `T`. // The pointer obtained is valid since it refers to memory owned by `slice` which is a // reference and thus guaranteed to be valid for reads. - &mut *(slice as *mut [MaybeUninit] as *mut [T]) + &mut *(core::ptr::from_mut::<[MaybeUninit]>(slice) as *mut [T]) } diff --git a/tiny-std/src/thread/spawn.rs b/tiny-std/src/thread/spawn.rs index c6dc3a9..c9b46a6 100644 --- a/tiny-std/src/thread/spawn.rs +++ b/tiny-std/src/thread/spawn.rs @@ -258,9 +258,9 @@ pub(crate) struct ThreadDealloc { /// Spawn a thread that will run the provided function /// # Errors /// Failure to mmap the thread's stack. -pub fn spawn T>(func: F) -> Result> +pub fn spawn(func: F) -> Result> where - F: Send + 'static, + F: FnOnce() -> T + Send + 'static, T: Send + 'static, { let flags = CloneFlags::CLONE_VM diff --git a/tiny-std/src/unix/passwd/getpw_r.rs b/tiny-std/src/unix/passwd/getpw_r.rs index baede31..51ad3dc 100644 --- a/tiny-std/src/unix/passwd/getpw_r.rs +++ b/tiny-std/src/unix/passwd/getpw_r.rs @@ -19,7 +19,7 @@ pub struct Passwd<'a> { /// `/etc/passwd` isn't readable. pub fn getpwuid_r(uid: UidT, buf: &mut [u8]) -> Result> { let fd = - unsafe { rusl::unistd::open_raw("/etc/passwd\0".as_ptr() as usize, OpenFlags::O_RDONLY)? }; + unsafe { rusl::unistd::open_raw(c"/etc/passwd".as_ptr() as usize, OpenFlags::O_RDONLY)? }; search_pwd_fd(fd, uid, buf) }