diff --git a/crates/printf/src/tests.rs b/crates/printf/src/tests.rs index 8c81f630c..98e713778 100644 --- a/crates/printf/src/tests.rs +++ b/crates/printf/src/tests.rs @@ -1,7 +1,6 @@ use crate::arg::ToArg; use crate::locale::{C_LOCALE, EN_US_LOCALE, Locale}; use crate::{Error, FormatString, sprintf_locale}; -use libc::c_char; use std::f64::consts::{E, PI, TAU}; use std::ffi::CStr; use std::fmt; @@ -890,10 +889,16 @@ fn libc_sprintf_one_float_with_precision<'a>( fmt: &'a CStr, ) -> impl FnMut(usize, f64) -> &'a str { |preci, float_val| unsafe { - let storage_ptr = storage.as_mut_ptr() as *mut c_char; - let len = libc::snprintf(storage_ptr, storage.len(), fmt.as_ptr(), preci, float_val); + let storage_ptr = storage.as_mut_ptr(); + let len = libc::snprintf( + storage_ptr.cast(), + storage.len(), + fmt.as_ptr(), + preci, + float_val, + ); assert!(len >= 0); - let sl = std::slice::from_raw_parts(storage_ptr as *const u8, len as usize); + let sl = std::slice::from_raw_parts(storage_ptr, len as usize); std::str::from_utf8(sl).unwrap() } } diff --git a/src/ast.rs b/src/ast.rs index 0412bf0b2..8c186e431 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -242,8 +242,8 @@ pub fn is_same_node(lhs: &dyn Node, rhs: &dyn Node) -> bool { // Note this is performance-sensitive. // Different base pointers => not the same. - let lptr = std::ptr::from_ref(lhs) as *const (); - let rptr = std::ptr::from_ref(rhs) as *const (); + let lptr = std::ptr::from_ref(lhs).cast::<()>(); + let rptr = std::ptr::from_ref(rhs).cast::<()>(); if !std::ptr::eq(lptr, rptr) { return false; } diff --git a/src/complete.rs b/src/complete.rs index b938ec837..b9de761af 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -1879,8 +1879,8 @@ fn apply_var_assignments>( let vars = parser.vars(); assert_eq!( - std::ptr::from_ref(self.ctx.vars()) as *const (), - std::ptr::from_ref(vars) as *const (), + std::ptr::from_ref(self.ctx.vars()).cast::<()>(), + std::ptr::from_ref(vars).cast::<()>(), "Don't know how to tab complete with a parser but a different variable set" ); diff --git a/src/exec.rs b/src/exec.rs index af5dfb775..bd1603829 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -49,7 +49,7 @@ use errno::{errno, set_errno}; use libc::{ EACCES, ENOENT, ENOEXEC, ENOTDIR, EPIPE, EXIT_FAILURE, EXIT_SUCCESS, STDERR_FILENO, - STDIN_FILENO, STDOUT_FILENO, c_char, + STDIN_FILENO, STDOUT_FILENO, }; use nix::fcntl::OFlag; use nix::sys::stat; @@ -414,7 +414,7 @@ fn safe_launch_process( if nargs <= MAXARGS { // +1 for /bin/sh, +1 for terminating nullptr let mut argv2 = [std::ptr::null(); 1 + MAXARGS + 1]; - let bshell = PATH_BSHELL.as_ptr() as *const c_char; + let bshell = PATH_BSHELL.as_ptr().cast(); argv2[0] = bshell; argv2[1..argv.len() + 1].copy_from_slice(argv); // The command to call should use the full path, diff --git a/src/fd_monitor.rs b/src/fd_monitor.rs index 634cbd9a9..dee4142f3 100644 --- a/src/fd_monitor.rs +++ b/src/fd_monitor.rs @@ -16,7 +16,7 @@ use crate::threads::assert_is_background_thread; use crate::wutil::perror; use errno::errno; -use libc::{EAGAIN, EINTR, EWOULDBLOCK, c_void}; +use libc::{EAGAIN, EINTR, EWOULDBLOCK}; cfg_if!( if #[cfg(have_eventfd)] { @@ -95,7 +95,7 @@ pub fn try_consume(&self) -> bool { ret = unsafe { libc::read( self.read_fd(), - buff.as_mut_ptr() as *mut c_void, + buff.as_mut_ptr().cast(), std::mem::size_of_val(&buff), ) }; diff --git a/src/fork_exec/flog_safe.rs b/src/fork_exec/flog_safe.rs index 033043ad8..d339dea86 100644 --- a/src/fork_exec/flog_safe.rs +++ b/src/fork_exec/flog_safe.rs @@ -85,7 +85,7 @@ pub fn flog_impl_async_safe(fd: i32, s: impl FloggableDisplayAsyncSafe) { // Note we deliberately do not retry on signals, etc. // This is used to report error messages after fork() in the child process. unsafe { - let _ = libc::write(fd, bytes.as_ptr() as *const libc::c_void, bytes.len()); + let _ = libc::write(fd, bytes.as_ptr().cast(), bytes.len()); } } diff --git a/src/fork_exec/spawn.rs b/src/fork_exec/spawn.rs index e2b3f80f8..f1c59cec7 100644 --- a/src/fork_exec/spawn.rs +++ b/src/fork_exec/spawn.rs @@ -172,7 +172,7 @@ pub(crate) fn spawn( let cmdcstr = unsafe { CStr::from_ptr(cmd) }; if spawn_err.0 == libc::ENOEXEC && is_thompson_shell_script(cmdcstr) { // Create a new argv with /bin/sh prepended. - let mut argv2: Vec<*mut c_char> = vec![PATH_BSHELL.as_ptr().cast_mut() as *mut c_char]; + let mut argv2 = vec![PATH_BSHELL.as_ptr().cast_mut().cast()]; // The command to call should use the full path, // not what we would pass as argv0. @@ -189,7 +189,7 @@ pub(crate) fn spawn( check_fail(unsafe { libc::posix_spawn( &mut pid, - PATH_BSHELL.as_ptr() as *const c_char, + PATH_BSHELL.as_ptr().cast(), &self.actions.0, &self.attr.0, argv2.as_ptr(), diff --git a/src/history/history.rs b/src/history/history.rs index 3609b6f16..b4d3f438c 100644 --- a/src/history/history.rs +++ b/src/history/history.rs @@ -1138,7 +1138,7 @@ fn format_history_record( let mut timestamp_str = [0_u8; MAX_TIMESTAMP_LENGTH]; if unsafe { libc::strftime( - timestamp_str.as_mut_ptr() as *mut libc::c_char, + timestamp_str.as_mut_ptr().cast(), MAX_TIMESTAMP_LENGTH, show_time_format.as_ptr(), timestamp.as_ptr(), diff --git a/src/io.rs b/src/io.rs index 7d78e5959..3d5e77b8b 100644 --- a/src/io.rs +++ b/src/io.rs @@ -494,11 +494,11 @@ pub fn new() -> Self { } pub fn remove(&mut self, element: &dyn IoData) { // Discard vtable pointers when comparing. - let e1 = std::ptr::from_ref(element) as *const (); + let e1 = std::ptr::from_ref(element).cast::<()>(); let idx = self .0 .iter() - .position(|e2| Arc::as_ptr(e2) as *const () == e1) + .position(|e2| Arc::as_ptr(e2).cast::<()>() == e1) .expect("Element not found"); self.0.remove(idx); } diff --git a/src/reader/reader.rs b/src/reader/reader.rs index b8691aa8f..448c3631d 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -5891,9 +5891,7 @@ fn check_for_orphaned_process(loop_count: usize, shell_pgid: libc::pid_t) -> boo } let mut tmp = 0 as libc::c_char; - if unsafe { libc::read(tty_fd.fd(), &raw mut tmp as *mut libc::c_void, 1) } < 0 - && errno().0 == EIO - { + if unsafe { libc::read(tty_fd.fd(), (&raw mut tmp).cast(), 1) } < 0 && errno().0 == EIO { we_think_we_are_orphaned = true; } } diff --git a/src/threads/threads.rs b/src/threads/threads.rs index 5bbdce76b..36648062a 100644 --- a/src/threads/threads.rs +++ b/src/threads/threads.rs @@ -455,11 +455,11 @@ fn std_thread_inherits_sigmask() { // Compare the sigset_t values unsafe { let t1_sigset_slice = std::slice::from_raw_parts( - &raw const t1_set as *const u8, + (&raw const t1_set).cast::(), core::mem::size_of::(), ); let t2_sigset_slice = std::slice::from_raw_parts( - &raw const t2_set as *const u8, + (&raw const t2_set).cast::(), core::mem::size_of::(), ); diff --git a/src/wutil/mod.rs b/src/wutil/mod.rs index 4a5725e2f..7d978ffc0 100644 --- a/src/wutil/mod.rs +++ b/src/wutil/mod.rs @@ -478,7 +478,7 @@ mod tests { use crate::fds::AutoCloseFd; use crate::tests::prelude::*; use crate::wchar::prelude::*; - use libc::{O_CREAT, O_RDWR, O_TRUNC, SEEK_SET, c_void}; + use libc::{O_CREAT, O_RDWR, O_TRUNC, SEEK_SET}; use rand::Rng; use std::{ffi::CString, ptr}; @@ -683,7 +683,7 @@ fn test_wwrite_to_fd() { if size == 0 { ptr::null_mut() } else { - contents.as_mut_ptr() as *mut c_void + contents.as_mut_ptr().cast() }, narrow.len(), )