From 48e0dfde0084908901b50fc8d5386c9669b8b4cf Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 23 Sep 2022 19:48:49 +0900 Subject: [PATCH] Use offset_of! instead of cfg-ed addr_of! --- crossbeam-epoch/build.rs | 3 --- crossbeam-epoch/src/atomic.rs | 12 +++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crossbeam-epoch/build.rs b/crossbeam-epoch/build.rs index 2a7563509..b3bd15a5a 100644 --- a/crossbeam-epoch/build.rs +++ b/crossbeam-epoch/build.rs @@ -48,9 +48,6 @@ fn main() { println!("cargo:rustc-cfg=crossbeam_no_atomic_cas"); } - if !cfg.probe_rustc_version(1, 51) { - println!("cargo:rustc-cfg=crossbeam_no_raw_ref_macros"); - } if !cfg.probe_rustc_version(1, 61) { println!("cargo:rustc-cfg=crossbeam_no_const_fn_trait_bound"); } diff --git a/crossbeam-epoch/src/atomic.rs b/crossbeam-epoch/src/atomic.rs index fb913352e..7fbacc18d 100644 --- a/crossbeam-epoch/src/atomic.rs +++ b/crossbeam-epoch/src/atomic.rs @@ -14,7 +14,9 @@ use crate::guard::Guard; use crate::primitive::sync::atomic::AtomicPtr; #[cfg(not(miri))] use crate::primitive::sync::atomic::AtomicUsize; + use crossbeam_utils::atomic::AtomicConsume; +use memoffset::offset_of; /// The error returned on failed compare-and-swap operation. pub struct CompareExchangeError<'g, T: ?Sized + Pointable, P: Pointer> { @@ -208,12 +210,12 @@ impl Pointable for [MaybeUninit] { unsafe fn as_ptr(ptr: *mut ()) -> *const Self { let array = ptr.cast::>(); - #[cfg(not(crossbeam_no_raw_ref_macros))] - let ptr = ptr::addr_of!((*array).elements) as *const _; - #[cfg(crossbeam_no_raw_ref_macros)] - let ptr = (*array).elements.as_ptr(); + let elements = array + .cast::() + .add(offset_of!(Array, elements)) + .cast::>(); // TODO: use ptr::slice_from_raw_parts once we bump MSRV to 1.42 - slice::from_raw_parts(ptr, (*array).len) + slice::from_raw_parts(elements, (*array).len) } unsafe fn as_mut_ptr(ptr: *mut ()) -> *mut Self {