Remove redundant uses of std::mem::zeroed()

We already use "inode: 0". 

See 7c2c7f5874 (Use uninit instead of zeroed, 2025-05-19).

Part of #12337
This commit is contained in:
Johannes Altmanninger
2026-05-22 14:09:35 +08:00
parent 78633cab0f
commit 2c6b76d5fe
3 changed files with 21 additions and 12 deletions

View File

@@ -326,9 +326,19 @@ fn update_metadata(old_file: &File, new_file: &File) {
// only be updated once every 10 milliseconds.
#[cfg(any(target_os = "linux", target_os = "android"))]
{
let mut times: [libc::timespec; 2] = unsafe { std::mem::zeroed() };
times[0].tv_nsec = libc::UTIME_OMIT; // don't change atime
if unsafe { libc::clock_gettime(libc::CLOCK_REALTIME, &mut times[1]) } == 0 {
use libc::timespec;
let mut time = timespec {
tv_sec: 0,
tv_nsec: 0,
};
if unsafe { libc::clock_gettime(libc::CLOCK_REALTIME, &mut time) } == 0 {
let times = [
timespec {
tv_sec: 0,
tv_nsec: libc::UTIME_OMIT, // don't change atime,
},
time,
];
unsafe {
// This accesses both times[0] and times[1]. Check `utimensat(2)` for details.
libc::futimens(new_file.as_raw_fd(), &times[0]);

View File

@@ -28,6 +28,7 @@
use nix::errno::Errno;
use nix::unistd;
use std::cell::Cell;
use std::mem::MaybeUninit;
use std::os::fd::AsRawFd as _;
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::{Condvar, Mutex, MutexGuard};
@@ -172,14 +173,12 @@ pub fn new() -> BinarySemaphore {
// On BSD sem_init uses a file descriptor under the hood which doesn't get CLOEXEC (see #7304).
// So use fast semaphores on Linux only.
#[cfg(target_os = "linux")]
{
// sem_t does not have an initializer in Rust so we use zeroed().
let sem = Box::pin(UnsafeCell::new(unsafe { std::mem::zeroed() }));
let res = unsafe { libc::sem_init(sem.get(), 0, 0) };
if res == 0 {
return Self::Semaphore(sem);
}
if let Some(sem) = {
let mut sem = MaybeUninit::uninit();
let res = unsafe { libc::sem_init(sem.as_mut_ptr(), 0, 0) };
(res == 0).then_some(unsafe { sem.assume_init() })
} {
return Self::Semaphore(Box::pin(UnsafeCell::new(sem)));
}
let pipes = fds::make_autoclose_pipes().expect("Failed to make pubsub pipes");

View File

@@ -83,7 +83,7 @@ pub fn dev_inode(&self) -> Option<DevInode> {
// Reset our fields.
fn reset(&mut self) {
self.name.clear();
self.inode = unsafe { std::mem::zeroed() };
self.inode = 0;
self.typ.set(None);
self.dev_inode.set(None);
}