From 6b39d2cf8cee0047802f3f5793b56046bb393209 Mon Sep 17 00:00:00 2001 From: WATANABE Yuki Date: Thu, 7 Nov 2024 23:54:47 +0900 Subject: [PATCH] Use &raw instead of addr_of! and addr_of_mut! in yash-env --- .github/workflows/ci.yml | 2 +- check-msrv.sh | 16 +++++++-------- yash-builtin/CHANGELOG.md | 8 ++++++++ yash-builtin/Cargo.toml | 2 +- yash-cli/CHANGELOG-lib.md | 8 ++++++++ yash-cli/Cargo.toml | 2 +- yash-env-test-helper/CHANGELOG.md | 2 ++ yash-env-test-helper/Cargo.toml | 2 +- yash-env/CHANGELOG.md | 2 ++ yash-env/Cargo.toml | 2 +- yash-env/src/system/real.rs | 26 ++++++++++++------------- yash-env/src/system/real/file_system.rs | 15 +++++++------- yash-env/src/system/real/signal.rs | 13 ++++++------- yash-prompt/CHANGELOG.md | 2 ++ yash-prompt/Cargo.toml | 2 +- yash-semantics/CHANGELOG.md | 8 ++++++++ yash-semantics/Cargo.toml | 2 +- 17 files changed, 70 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f8e9e05..aae1d023 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly - uses: dtolnay/rust-toolchain@1.65.0 - - uses: dtolnay/rust-toolchain@1.79.0 + - uses: dtolnay/rust-toolchain@1.82.0 - uses: Swatinem/rust-cache@v2 - name: Run tests with MSRV run: ./check-msrv.sh -v diff --git a/check-msrv.sh b/check-msrv.sh index cc1a6ea8..42ced804 100755 --- a/check-msrv.sh +++ b/check-msrv.sh @@ -22,19 +22,19 @@ cargo +1.65.0 test --package yash-arith -- $quiet update_workspace_member yash-builtin cargo +nightly update -Z direct-minimal-versions -cargo +1.79.0 test --package yash-builtin -- $quiet +cargo +1.82.0 test --package yash-builtin -- $quiet update_workspace_member yash-cli cargo +nightly update -Z direct-minimal-versions -cargo +1.79.0 test --package yash-cli -- $quiet +cargo +1.82.0 test --package yash-cli -- $quiet update_workspace_member yash-env cargo +nightly update -Z direct-minimal-versions -cargo +1.79.0 test --package yash-env -- $quiet +cargo +1.82.0 test --package yash-env -- $quiet update_workspace_member yash-env-test-helper cargo +nightly update -Z direct-minimal-versions -cargo +1.79.0 test --package yash-env-test-helper -- $quiet +cargo +1.82.0 test --package yash-env-test-helper -- $quiet update_workspace_member yash-executor cargo +nightly update -Z direct-minimal-versions @@ -46,7 +46,7 @@ cargo +1.65.0 test --package yash-fnmatch -- $quiet update_workspace_member yash-prompt cargo +nightly update -Z direct-minimal-versions -cargo +1.79.0 test --package yash-prompt -- $quiet +cargo +1.82.0 test --package yash-prompt -- $quiet update_workspace_member yash-quote cargo +nightly update -Z direct-minimal-versions @@ -54,9 +54,9 @@ cargo +1.65.0 test --package yash-quote -- $quiet update_workspace_member yash-semantics cargo +nightly update -Z direct-minimal-versions -cargo +1.79.0 test --package yash-semantics -- $quiet +cargo +1.82.0 test --package yash-semantics -- $quiet update_workspace_member yash-syntax cargo +nightly update -Z direct-minimal-versions -cargo +1.79.0 test --package yash-syntax -- $quiet -cargo +1.79.0 test --package yash-syntax --features annotate-snippets -- $quiet +cargo +1.82.0 test --package yash-syntax -- $quiet +cargo +1.82.0 test --package yash-syntax --features annotate-snippets -- $quiet diff --git a/yash-builtin/CHANGELOG.md b/yash-builtin/CHANGELOG.md index a11220f8..2c963356 100644 --- a/yash-builtin/CHANGELOG.md +++ b/yash-builtin/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to `yash-builtin` will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.1] - Unreleased + +### Changed + +- External dependency versions: + - Rust 1.79.0 → 1.82.0 + ## [0.4.0] - 2024-09-29 ### Added @@ -123,6 +130,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial implementation of the `yash-builtin` crate +[0.4.1]: https://github.com/magicant/yash-rs/releases/tag/yash-builtin-0.4.1 [0.4.0]: https://github.com/magicant/yash-rs/releases/tag/yash-builtin-0.4.0 [0.3.0]: https://github.com/magicant/yash-rs/releases/tag/yash-builtin-0.3.0 [0.2.0]: https://github.com/magicant/yash-rs/releases/tag/yash-builtin-0.2.0 diff --git a/yash-builtin/Cargo.toml b/yash-builtin/Cargo.toml index 7815ad6a..df661eb6 100644 --- a/yash-builtin/Cargo.toml +++ b/yash-builtin/Cargo.toml @@ -3,7 +3,7 @@ name = "yash-builtin" version = "0.4.0" authors = ["WATANABE Yuki "] edition = "2021" -rust-version = "1.79.0" +rust-version = "1.82.0" description = "Implementation of the built-in utilities of yash" # documentation = "https://yash.osdn.jp/doc/" readme = "README.md" diff --git a/yash-cli/CHANGELOG-lib.md b/yash-cli/CHANGELOG-lib.md index a307b603..72165856 100644 --- a/yash-cli/CHANGELOG-lib.md +++ b/yash-cli/CHANGELOG-lib.md @@ -9,6 +9,13 @@ For changes to the shell binary as a whole, see [CHANGELOG-bin.md](CHANGELOG-bin The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.1] - Unreleased + +### Changed + +- External dependency versions: + - Rust 1.79.0 → 1.82.0 + ## [0.1.0] - 2024-09-29 ### Added @@ -121,6 +128,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial implementation of the `yash-cli` crate +[0.1.1]: https://github.com/magicant/yash-rs/releases/tag/yash-cli-0.1.1 [0.1.0]: https://github.com/magicant/yash-rs/releases/tag/yash-cli-0.1.0 [0.1.0-beta.2]: https://github.com/magicant/yash-rs/releases/tag/yash-cli-0.1.0-beta.2 [0.1.0-beta.1]: https://github.com/magicant/yash-rs/releases/tag/yash-cli-0.1.0-beta.1 diff --git a/yash-cli/Cargo.toml b/yash-cli/Cargo.toml index 1e1b6360..644ac229 100644 --- a/yash-cli/Cargo.toml +++ b/yash-cli/Cargo.toml @@ -3,7 +3,7 @@ name = "yash-cli" version = "0.1.0" authors = ["WATANABE Yuki "] edition = "2021" -rust-version = "1.79.0" +rust-version = "1.82.0" description = "Extended POSIX shell" # documentation = "https://yash.osdn.jp/doc/" readme = "README.md" diff --git a/yash-env-test-helper/CHANGELOG.md b/yash-env-test-helper/CHANGELOG.md index ba48f08b..7d33afed 100644 --- a/yash-env-test-helper/CHANGELOG.md +++ b/yash-env-test-helper/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- External dependency versions: + - Rust 1.79.0 → 1.82.0 - Internal dependency versions: - futures-executor 0.3.28 → 0.3.31 - futures-util 0.3.28 → 0.3.31 diff --git a/yash-env-test-helper/Cargo.toml b/yash-env-test-helper/Cargo.toml index 63a36c94..a30b55a7 100644 --- a/yash-env-test-helper/Cargo.toml +++ b/yash-env-test-helper/Cargo.toml @@ -3,7 +3,7 @@ name = "yash-env-test-helper" version = "0.2.0" authors = ["WATANABE Yuki "] edition = "2021" -rust-version = "1.79.0" +rust-version = "1.82.0" description = "Test helper for yash-env crate" # documentation = "https://yash.osdn.jp/doc/" readme = "README.md" diff --git a/yash-env/CHANGELOG.md b/yash-env/CHANGELOG.md index fdc5fb4f..6b2993eb 100644 --- a/yash-env/CHANGELOG.md +++ b/yash-env/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- External dependency versions: + - Rust 1.79.0 → 1.82.0 - Internal dependency versions: - futures-util 0.3.28 → 0.3.31 diff --git a/yash-env/Cargo.toml b/yash-env/Cargo.toml index 14db8fb6..d59b2124 100644 --- a/yash-env/Cargo.toml +++ b/yash-env/Cargo.toml @@ -3,7 +3,7 @@ name = "yash-env" version = "0.4.0" authors = ["WATANABE Yuki "] edition = "2021" -rust-version = "1.79.0" +rust-version = "1.82.0" description = "Yash shell execution environment interface" # documentation = "https://yash.osdn.jp/doc/" readme = "README.md" diff --git a/yash-env/src/system/real.rs b/yash-env/src/system/real.rs index 4955a830..7b5ad39b 100644 --- a/yash-env/src/system/real.rs +++ b/yash-env/src/system/real.rs @@ -76,8 +76,6 @@ use std::os::unix::ffi::OsStrExt as _; use std::os::unix::ffi::OsStringExt as _; use std::os::unix::io::IntoRawFd; use std::pin::Pin; -use std::ptr::addr_of; -use std::ptr::addr_of_mut; use std::ptr::NonNull; use std::sync::atomic::compiler_fence; use std::sync::atomic::AtomicIsize; @@ -162,8 +160,8 @@ fn to_timespec(duration: Duration) -> MaybeUninit { .unwrap_or(nix::libc::time_t::MAX); let mut timespec = MaybeUninit::::uninit(); unsafe { - addr_of_mut!((*timespec.as_mut_ptr()).tv_sec).write(seconds); - addr_of_mut!((*timespec.as_mut_ptr()).tv_nsec).write(duration.subsec_nanos() as _); + (&raw mut (*timespec.as_mut_ptr()).tv_sec).write(seconds); + (&raw mut (*timespec.as_mut_ptr()).tv_nsec).write(duration.subsec_nanos() as _); } timespec } @@ -434,10 +432,10 @@ impl System for RealSystem { // SAFETY: The four fields of `tms` have been initialized by `times`. // (But that does not mean *all* fields are initialized, // so we cannot use `assume_init` here.) - let utime = unsafe { addr_of!((*tms.as_ptr()).tms_utime).read() }; - let stime = unsafe { addr_of!((*tms.as_ptr()).tms_stime).read() }; - let cutime = unsafe { addr_of!((*tms.as_ptr()).tms_cutime).read() }; - let cstime = unsafe { addr_of!((*tms.as_ptr()).tms_cstime).read() }; + let utime = unsafe { (&raw const (*tms.as_ptr()).tms_utime).read() }; + let stime = unsafe { (&raw const (*tms.as_ptr()).tms_stime).read() }; + let cutime = unsafe { (&raw const (*tms.as_ptr()).tms_cutime).read() }; + let cstime = unsafe { (&raw const (*tms.as_ptr()).tms_cstime).read() }; Ok(Times { self_user: utime as f64 / ticks_per_second as f64, @@ -518,7 +516,7 @@ impl System for RealSystem { let new_action = handling.to_sigaction(); let mut old_action = MaybeUninit::::uninit(); - let old_mask_ptr = addr_of_mut!((*old_action.as_mut_ptr()).sa_mask); + let old_mask_ptr = &raw mut (*old_action.as_mut_ptr()).sa_mask; // POSIX requires *all* sigset_t objects to be initialized before use. nix::libc::sigemptyset(old_mask_ptr).errno_if_m1()?; @@ -838,8 +836,8 @@ impl System for RealSystem { let mut limits = MaybeUninit::::uninit(); unsafe { nix::libc::getrlimit(raw_resource as _, limits.as_mut_ptr()) }.errno_if_m1()?; Ok(LimitPair { - soft: unsafe { addr_of!((*limits.as_ptr()).rlim_cur).read() }, - hard: unsafe { addr_of!((*limits.as_ptr()).rlim_max).read() }, + soft: unsafe { (&raw const (*limits.as_ptr()).rlim_cur).read() }, + hard: unsafe { (&raw const (*limits.as_ptr()).rlim_max).read() }, }) } @@ -848,8 +846,8 @@ impl System for RealSystem { let mut rlimit = MaybeUninit::::uninit(); unsafe { - addr_of_mut!((*rlimit.as_mut_ptr()).rlim_cur).write(limits.soft); - addr_of_mut!((*rlimit.as_mut_ptr()).rlim_max).write(limits.hard); + (&raw mut (*rlimit.as_mut_ptr()).rlim_cur).write(limits.soft); + (&raw mut (*rlimit.as_mut_ptr()).rlim_max).write(limits.hard); } unsafe { nix::libc::setrlimit(raw_resource as _, rlimit.as_ptr()) }.errno_if_m1()?; @@ -882,7 +880,7 @@ impl Dir for RealDir { } } else { // TODO Use as_ptr rather than cast when array_ptr_get is stabilized - let name = unsafe { CStr::from_ptr(addr_of!((*entry).d_name).cast()) }; + let name = unsafe { CStr::from_ptr((&raw const (*entry).d_name).cast()) }; let name = UnixStr::from_bytes(name.to_bytes()); Ok(Some(DirEntry { name })) } diff --git a/yash-env/src/system/real/file_system.rs b/yash-env/src/system/real/file_system.rs index b785916e..f88fa42d 100644 --- a/yash-env/src/system/real/file_system.rs +++ b/yash-env/src/system/real/file_system.rs @@ -18,7 +18,6 @@ use super::super::{FileType, Gid, Mode, RawMode, Stat, Uid}; use std::mem::MaybeUninit; -use std::ptr::addr_of; impl FileType { #[must_use] @@ -45,16 +44,16 @@ impl Stat { #[must_use] pub(super) const fn from_raw(stat: &MaybeUninit) -> Self { let ptr = stat.as_ptr(); - let raw_mode = unsafe { addr_of!((*ptr).st_mode).read() }; + let raw_mode = unsafe { (&raw const (*ptr).st_mode).read() }; Self { - dev: unsafe { addr_of!((*ptr).st_dev).read() } as _, - ino: unsafe { addr_of!((*ptr).st_ino).read() } as _, + dev: unsafe { (&raw const (*ptr).st_dev).read() } as _, + ino: unsafe { (&raw const (*ptr).st_ino).read() } as _, mode: Mode::from_bits_truncate(raw_mode), r#type: FileType::from_raw(raw_mode), - nlink: unsafe { addr_of!((*ptr).st_nlink).read() } as _, - uid: Uid(unsafe { addr_of!((*ptr).st_uid).read() }), - gid: Gid(unsafe { addr_of!((*ptr).st_gid).read() }), - size: unsafe { addr_of!((*ptr).st_size).read() } as _, + nlink: unsafe { (&raw const (*ptr).st_nlink).read() } as _, + uid: Uid(unsafe { (&raw const (*ptr).st_uid).read() }), + gid: Gid(unsafe { (&raw const (*ptr).st_gid).read() }), + size: unsafe { (&raw const (*ptr).st_size).read() } as _, } } } diff --git a/yash-env/src/system/real/signal.rs b/yash-env/src/system/real/signal.rs index 954d36e3..50e5b487 100644 --- a/yash-env/src/system/real/signal.rs +++ b/yash-env/src/system/real/signal.rs @@ -22,7 +22,6 @@ use std::ffi::c_int; use std::mem::MaybeUninit; use std::num::NonZeroI32; use std::ops::RangeInclusive; -use std::ptr::{addr_of, addr_of_mut}; /// Returns the range of real-time signals supported by the real system. /// @@ -437,16 +436,16 @@ impl Disposition { let mut sa = MaybeUninit::::uninit(); let sa_ptr = sa.as_mut_ptr(); unsafe { - addr_of_mut!((*sa_ptr).sa_flags).write(0); - nix::libc::sigemptyset(addr_of_mut!((*sa_ptr).sa_mask)); + (&raw mut (*sa_ptr).sa_flags).write(0); + nix::libc::sigemptyset(&raw mut ((*sa_ptr).sa_mask)); #[cfg(not(target_os = "aix"))] #[allow(clippy::useless_transmute)] // See from_sigaction below - addr_of_mut!((*sa_ptr).sa_sigaction).write(std::mem::transmute(handler)); + (&raw mut (*sa_ptr).sa_sigaction).write(std::mem::transmute(handler)); #[cfg(target_os = "aix")] #[allow(clippy::useless_transmute)] // See from_sigaction below - addr_of_mut!((*sa_ptr).sa_union.__su_sigaction).write(std::mem::transmute(handler)); + (&raw mut (*sa_ptr).sa_union.__su_sigaction).write(std::mem::transmute(handler)); } sa } @@ -454,10 +453,10 @@ impl Disposition { /// Converts the `sigaction` to the signal disposition for the real system. pub(super) unsafe fn from_sigaction(sa: &MaybeUninit) -> Self { #[cfg(not(target_os = "aix"))] - let handler = addr_of!((*sa.as_ptr()).sa_sigaction).read(); + let handler = (&raw const (*sa.as_ptr()).sa_sigaction).read(); #[cfg(target_os = "aix")] - let handler = addr_of!((*sa.as_ptr()).sa_union.__su_sigaction).read(); + let handler = (&raw const (*sa.as_ptr()).sa_union.__su_sigaction).read(); // It is platform-specific whether we really need to transmute the handler. #[allow(clippy::useless_transmute)] diff --git a/yash-prompt/CHANGELOG.md b/yash-prompt/CHANGELOG.md index e7145b33..b3b3ee78 100644 --- a/yash-prompt/CHANGELOG.md +++ b/yash-prompt/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- External dependency versions: + - Rust 1.79.0 → 1.82.0 - Internal dependency versions: - futures-util 0.3.28 → 0.3.31 diff --git a/yash-prompt/Cargo.toml b/yash-prompt/Cargo.toml index df8de7e8..94f9bc88 100644 --- a/yash-prompt/Cargo.toml +++ b/yash-prompt/Cargo.toml @@ -3,7 +3,7 @@ name = "yash-prompt" version = "0.2.0" authors = ["WATANABE Yuki "] edition = "2021" -rust-version = "1.79.0" +rust-version = "1.82.0" description = "Command line prompt for yash shell" # documentation = "https://yash.osdn.jp/doc/" readme = "README.md" diff --git a/yash-semantics/CHANGELOG.md b/yash-semantics/CHANGELOG.md index 737a8f4d..279cba1e 100644 --- a/yash-semantics/CHANGELOG.md +++ b/yash-semantics/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to `yash-semantics` will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.1] - Unreleased + +### Changed + +- External dependency versions: + - Rust 1.79.0 → 1.82.0 + ## [0.4.0] - 2024-09-29 ### Added @@ -128,6 +135,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial implementation of the `yash-semantics` crate +[0.4.1]: https://github.com/magicant/yash-rs/releases/tag/yash-semantics-0.4.1 [0.4.0]: https://github.com/magicant/yash-rs/releases/tag/yash-semantics-0.4.0 [0.3.0]: https://github.com/magicant/yash-rs/releases/tag/yash-semantics-0.3.0 [0.2.0]: https://github.com/magicant/yash-rs/releases/tag/yash-semantics-0.2.0 diff --git a/yash-semantics/Cargo.toml b/yash-semantics/Cargo.toml index 59e59d01..8b309c89 100644 --- a/yash-semantics/Cargo.toml +++ b/yash-semantics/Cargo.toml @@ -3,7 +3,7 @@ name = "yash-semantics" version = "0.4.0" authors = ["WATANABE Yuki "] edition = "2021" -rust-version = "1.79.0" +rust-version = "1.82.0" description = "Yash shell language semantics" # documentation = "https://yash.osdn.jp/doc/" readme = "README.md"