From 717d301b7f7acadcc2b25684ea14e13d2e6a48ce Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Thu, 4 Dec 2025 17:41:51 +0000 Subject: [PATCH] refactor: replace `addr_of!` macros with raw pointer syntax `addr_of!` and `addr_of_mut!` have been soft-deprecated as of Rust 1.82.0. Closes #12139 --- src/fork_exec/postfork.rs | 8 +------- src/io.rs | 16 ++++------------ src/wutil/dir_iter.rs | 6 ++---- src/wutil/mod.rs | 8 +------- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/fork_exec/postfork.rs b/src/fork_exec/postfork.rs index f585188a9..97955cea6 100644 --- a/src/fork_exec/postfork.rs +++ b/src/fork_exec/postfork.rs @@ -495,13 +495,7 @@ fn get_interpreter<'a>(command: &CStr, buffer: &'a mut [u8]) -> Option<&'a CStr> if fd >= 0 { while idx + 1 < buffer.len() { let mut ch = b'\0'; - let amt = unsafe { - libc::read( - fd, - std::ptr::addr_of_mut!(ch).cast(), - std::mem::size_of_val(&ch), - ) - }; + let amt = unsafe { libc::read(fd, (&raw mut ch).cast(), std::mem::size_of_val(&ch)) }; if amt <= 0 || ch == b'\n' { break; } diff --git a/src/io.rs b/src/io.rs index 2e949bb04..9c888150b 100644 --- a/src/io.rs +++ b/src/io.rs @@ -417,13 +417,8 @@ pub fn read_once(fd: RawFd, buffer: &mut MutexGuard<'_, SeparatedBuffer>) -> isi // We want to swallow EINTR only; in particular EAGAIN needs to be returned back to the caller. let amt = loop { - let amt = unsafe { - libc::read( - fd, - std::ptr::addr_of_mut!(bytes).cast(), - std::mem::size_of_val(&bytes), - ) - }; + let amt = + unsafe { libc::read(fd, bytes.as_mut_ptr().cast(), std::mem::size_of_val(&bytes)) }; if amt < 0 && errno::errno().0 == EINTR { continue; } @@ -623,16 +618,13 @@ pub fn append_from_specs(&mut self, specs: &RedirectionSpecList, pwd: &wstr) -> /// Output debugging information to stderr. pub fn print(&self) { if self.0.is_empty() { - eprintf!( - "Empty chain %s\n", - format!("{:p}", std::ptr::addr_of!(self)) - ); + eprintf!("Empty chain %s\n", format!("{:p}", &raw const self)); return; } eprintf!( "Chain %s (%d items):\n", - format!("{:p}", std::ptr::addr_of!(self)), + format!("{:p}", &raw const self), self.0.len() ); for (i, io) in self.0.iter().enumerate() { diff --git a/src/wutil/dir_iter.rs b/src/wutil/dir_iter.rs index 165075b4b..4232f43ad 100644 --- a/src/wutil/dir_iter.rs +++ b/src/wutil/dir_iter.rs @@ -12,7 +12,7 @@ use std::io; use std::mem::MaybeUninit; use std::os::fd::RawFd; -use std::ptr::{NonNull, addr_of}; +use std::ptr::NonNull; use std::rc::Rc; /// Types of files that may be in a directory. @@ -273,11 +273,9 @@ pub fn next(&mut self) -> Option> { // Do not rely on `libc::dirent::d_name.len()` as dirent names may exceed // the nominal buffer size; instead use the terminating nul byte. - // TODO: This should use &raw from Rust 1.82 on // https://github.com/rust-lang/libc/issues/2669 // https://github.com/fish-shell/fish-shell/issues/11221 - let d_name_ptr = addr_of!(dent.d_name); - let d_name = unsafe { std::ffi::CStr::from_ptr(d_name_ptr.cast()) }.to_bytes(); + let d_name = unsafe { std::ffi::CStr::from_ptr(dent.d_name.as_ptr().cast()) }.to_bytes(); // Skip . and .., // unless we've been told not to. diff --git a/src/wutil/mod.rs b/src/wutil/mod.rs index 41f81363b..73caf5b44 100644 --- a/src/wutil/mod.rs +++ b/src/wutil/mod.rs @@ -115,13 +115,7 @@ pub fn wreadlink(file_name: &wstr) -> Option { let bufsize = usize::try_from(md.len()).unwrap() + 1; let mut target_buf = vec![b'\0'; bufsize]; let tmp = wcs2zstring(file_name); - let nbytes = unsafe { - libc::readlink( - tmp.as_ptr(), - std::ptr::addr_of_mut!(target_buf[0]).cast(), - bufsize, - ) - }; + let nbytes = unsafe { libc::readlink(tmp.as_ptr(), target_buf.as_mut_ptr().cast(), bufsize) }; if nbytes == -1 { perror("readlink"); return None;