Skip to content

Commit

Permalink
Use offset_of! instead of cfg-ed addr_of!
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 23, 2022
1 parent 9d1ebd2 commit 48e0dfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 0 additions & 3 deletions crossbeam-epoch/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
12 changes: 7 additions & 5 deletions crossbeam-epoch/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>> {
Expand Down Expand Up @@ -208,12 +210,12 @@ impl<T> Pointable for [MaybeUninit<T>] {

unsafe fn as_ptr(ptr: *mut ()) -> *const Self {
let array = ptr.cast::<Array<T>>();
#[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::<u8>()
.add(offset_of!(Array<T>, elements))
.cast::<MaybeUninit<T>>();
// 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 {
Expand Down

0 comments on commit 48e0dfd

Please sign in to comment.