Skip to content

Commit

Permalink
Update to new lints
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusGrass committed May 5, 2024
1 parent c04ae75 commit accd840
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rusl/src/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TimeSpec>),
0,
0
)
Expand Down
2 changes: 1 addition & 1 deletion rusl/src/platform/compat/io_uring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TimeSpec>(ts) as u64,
},
len: 1,
__bindgen_anon_3: io_uring_sqe__bindgen_ty_3 {
Expand Down
2 changes: 1 addition & 1 deletion rusl/src/platform/compat/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down
4 changes: 2 additions & 2 deletions rusl/src/select/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TimeSpec>),
sigset.map_or_else(core::ptr::null, core::ptr::from_ref::<SigSetT>)
)
};
bail_on_below_zero!(res, "`PPOLL` syscall failed");
Expand Down
10 changes: 6 additions & 4 deletions rusl/src/string/unix_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}

Expand Down Expand Up @@ -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"))
};
Expand All @@ -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`
Expand Down Expand Up @@ -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
};
Expand Down
1 change: 1 addition & 0 deletions tiny-std/src/allocator/dlmalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tiny-std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tiny-std/src/io/read_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,5 @@ pub(crate) unsafe fn slice_assume_init_mut<T>(slice: &mut [MaybeUninit<T>]) -> &
// `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<T>] as *mut [T])
&mut *(core::ptr::from_mut::<[MaybeUninit<T>]>(slice) as *mut [T])
}
4 changes: 2 additions & 2 deletions tiny-std/src/thread/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, F: FnOnce() -> T>(func: F) -> Result<JoinHandle<T>>
pub fn spawn<T, F>(func: F) -> Result<JoinHandle<T>>
where
F: Send + 'static,
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
let flags = CloneFlags::CLONE_VM
Expand Down
2 changes: 1 addition & 1 deletion tiny-std/src/unix/passwd/getpw_r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Passwd<'a> {
/// `/etc/passwd` isn't readable.
pub fn getpwuid_r(uid: UidT, buf: &mut [u8]) -> Result<Option<Passwd>> {
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)
}

Expand Down

0 comments on commit accd840

Please sign in to comment.