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
This commit is contained in:
xtqqczze
2025-12-04 17:41:51 +00:00
committed by Johannes Altmanninger
parent 6a36d92173
commit 717d301b7f
4 changed files with 8 additions and 30 deletions

View File

@@ -495,13 +495,7 @@ fn get_interpreter<'a>(command: &CStr, buffer: &'a mut [u8]) -> Option<&'a CStr>
if fd >= 0 { if fd >= 0 {
while idx + 1 < buffer.len() { while idx + 1 < buffer.len() {
let mut ch = b'\0'; let mut ch = b'\0';
let amt = unsafe { let amt = unsafe { libc::read(fd, (&raw mut ch).cast(), std::mem::size_of_val(&ch)) };
libc::read(
fd,
std::ptr::addr_of_mut!(ch).cast(),
std::mem::size_of_val(&ch),
)
};
if amt <= 0 || ch == b'\n' { if amt <= 0 || ch == b'\n' {
break; break;
} }

View File

@@ -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. // We want to swallow EINTR only; in particular EAGAIN needs to be returned back to the caller.
let amt = loop { let amt = loop {
let amt = unsafe { let amt =
libc::read( unsafe { libc::read(fd, bytes.as_mut_ptr().cast(), std::mem::size_of_val(&bytes)) };
fd,
std::ptr::addr_of_mut!(bytes).cast(),
std::mem::size_of_val(&bytes),
)
};
if amt < 0 && errno::errno().0 == EINTR { if amt < 0 && errno::errno().0 == EINTR {
continue; continue;
} }
@@ -623,16 +618,13 @@ pub fn append_from_specs(&mut self, specs: &RedirectionSpecList, pwd: &wstr) ->
/// Output debugging information to stderr. /// Output debugging information to stderr.
pub fn print(&self) { pub fn print(&self) {
if self.0.is_empty() { if self.0.is_empty() {
eprintf!( eprintf!("Empty chain %s\n", format!("{:p}", &raw const self));
"Empty chain %s\n",
format!("{:p}", std::ptr::addr_of!(self))
);
return; return;
} }
eprintf!( eprintf!(
"Chain %s (%d items):\n", "Chain %s (%d items):\n",
format!("{:p}", std::ptr::addr_of!(self)), format!("{:p}", &raw const self),
self.0.len() self.0.len()
); );
for (i, io) in self.0.iter().enumerate() { for (i, io) in self.0.iter().enumerate() {

View File

@@ -12,7 +12,7 @@
use std::io; use std::io;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::os::fd::RawFd; use std::os::fd::RawFd;
use std::ptr::{NonNull, addr_of}; use std::ptr::NonNull;
use std::rc::Rc; use std::rc::Rc;
/// Types of files that may be in a directory. /// Types of files that may be in a directory.
@@ -273,11 +273,9 @@ pub fn next(&mut self) -> Option<io::Result<&DirEntry>> {
// Do not rely on `libc::dirent::d_name.len()` as dirent names may exceed // Do not rely on `libc::dirent::d_name.len()` as dirent names may exceed
// the nominal buffer size; instead use the terminating nul byte. // 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/rust-lang/libc/issues/2669
// https://github.com/fish-shell/fish-shell/issues/11221 // 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(dent.d_name.as_ptr().cast()) }.to_bytes();
let d_name = unsafe { std::ffi::CStr::from_ptr(d_name_ptr.cast()) }.to_bytes();
// Skip . and .., // Skip . and ..,
// unless we've been told not to. // unless we've been told not to.

View File

@@ -115,13 +115,7 @@ pub fn wreadlink(file_name: &wstr) -> Option<WString> {
let bufsize = usize::try_from(md.len()).unwrap() + 1; let bufsize = usize::try_from(md.len()).unwrap() + 1;
let mut target_buf = vec![b'\0'; bufsize]; let mut target_buf = vec![b'\0'; bufsize];
let tmp = wcs2zstring(file_name); let tmp = wcs2zstring(file_name);
let nbytes = unsafe { let nbytes = unsafe { libc::readlink(tmp.as_ptr(), target_buf.as_mut_ptr().cast(), bufsize) };
libc::readlink(
tmp.as_ptr(),
std::ptr::addr_of_mut!(target_buf[0]).cast(),
bufsize,
)
};
if nbytes == -1 { if nbytes == -1 {
perror("readlink"); perror("readlink");
return None; return None;