From d487ba2b9bbe748be2e5e9423b408f7b73a439fb Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 29 Jul 2025 11:01:31 +0300 Subject: [PATCH] Replace 'memoffset' crate with core functionality (#12761) The `std::mem::offset_of` macro was introduced in Rust 1.77.0. In the passing, mark the function as `const`, as suggested in the comment. Not sure which compiler version that requires, but it works with what have currently. --- Cargo.lock | 1 - Cargo.toml | 1 - libs/postgres_ffi/Cargo.toml | 1 - libs/postgres_ffi/src/controlfile_utils.rs | 5 ++--- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c15a47c96..1919f8e99d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5078,7 +5078,6 @@ dependencies = [ "criterion", "env_logger", "log", - "memoffset 0.9.0", "once_cell", "postgres", "postgres_ffi_types", diff --git a/Cargo.toml b/Cargo.toml index 8051b3ee3e..3f23086797 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,7 +135,6 @@ lock_api = "0.4.13" md5 = "0.7.0" measured = { version = "0.0.22", features=["lasso"] } measured-process = { version = "0.0.22" } -memoffset = "0.9" moka = { version = "0.12", features = ["sync"] } nix = { version = "0.30.1", features = ["dir", "fs", "mman", "process", "socket", "signal", "poll"] } # Do not update to >= 7.0.0, at least. The update will have a significant impact diff --git a/libs/postgres_ffi/Cargo.toml b/libs/postgres_ffi/Cargo.toml index d4fec6cbe9..fca75b7bc1 100644 --- a/libs/postgres_ffi/Cargo.toml +++ b/libs/postgres_ffi/Cargo.toml @@ -12,7 +12,6 @@ crc32c.workspace = true criterion.workspace = true once_cell.workspace = true log.workspace = true -memoffset.workspace = true pprof.workspace = true thiserror.workspace = true serde.workspace = true diff --git a/libs/postgres_ffi/src/controlfile_utils.rs b/libs/postgres_ffi/src/controlfile_utils.rs index eaa9450294..d6d17ce3fb 100644 --- a/libs/postgres_ffi/src/controlfile_utils.rs +++ b/libs/postgres_ffi/src/controlfile_utils.rs @@ -34,9 +34,8 @@ const SIZEOF_CONTROLDATA: usize = size_of::(); impl ControlFileData { /// Compute the offset of the `crc` field within the `ControlFileData` struct. /// Equivalent to offsetof(ControlFileData, crc) in C. - // Someday this can be const when the right compiler features land. - fn pg_control_crc_offset() -> usize { - memoffset::offset_of!(ControlFileData, crc) + const fn pg_control_crc_offset() -> usize { + std::mem::offset_of!(ControlFileData, crc) } ///