diff --git a/src/allocation.rs b/src/allocation.rs index 8c29864d..9d6c0e6a 100644 --- a/src/allocation.rs +++ b/src/allocation.rs @@ -10,11 +10,12 @@ //! ["extern_crate_alloc"]}` use super::*; +#[cfg(target_has_atomic = "ptr")] +use alloc::sync::Arc; use alloc::{ alloc::{alloc_zeroed, Layout}, boxed::Box, rc::Rc, - sync::Arc, vec, vec::Vec, }; @@ -355,6 +356,7 @@ pub fn try_cast_rc( /// As [`try_cast_arc`](try_cast_arc), but unwraps for you. #[inline] +#[cfg(target_has_atomic = "ptr")] pub fn cast_arc( input: Arc, ) -> Arc { @@ -375,6 +377,7 @@ pub fn cast_arc( /// alignment. /// * The start and end size of the `Arc` must have the exact same size. #[inline] +#[cfg(target_has_atomic = "ptr")] pub fn try_cast_arc< A: NoUninit + AnyBitPattern, B: NoUninit + AnyBitPattern, @@ -456,6 +459,7 @@ pub fn try_cast_slice_rc< /// As [`try_cast_slice_arc`](try_cast_slice_arc), but unwraps for you. #[inline] +#[cfg(target_has_atomic = "ptr")] pub fn cast_slice_arc< A: NoUninit + AnyBitPattern, B: NoUninit + AnyBitPattern, @@ -480,6 +484,7 @@ pub fn cast_slice_arc< /// * The start and end content size in bytes of the `Arc<[T]>` must be the /// exact same. #[inline] +#[cfg(target_has_atomic = "ptr")] pub fn try_cast_slice_arc< A: NoUninit + AnyBitPattern, B: NoUninit + AnyBitPattern, @@ -590,6 +595,7 @@ pub trait TransparentWrapperAlloc: /// Convert an [`Arc`](alloc::sync::Arc) to the inner type into an `Arc` to /// the wrapper type. #[inline] + #[cfg(target_has_atomic = "ptr")] fn wrap_arc(s: Arc) -> Arc { assert!(size_of::<*mut Inner>() == size_of::<*mut Self>()); @@ -679,6 +685,7 @@ pub trait TransparentWrapperAlloc: /// Convert an [`Arc`](alloc::sync::Arc) to the wrapper type into an `Arc` to /// the inner type. #[inline] + #[cfg(target_has_atomic = "ptr")] fn peel_arc(s: Arc) -> Arc { assert!(size_of::<*mut Inner>() == size_of::<*mut Self>()); diff --git a/tests/transparent.rs b/tests/transparent.rs index 78d4fe16..be26c218 100644 --- a/tests/transparent.rs +++ b/tests/transparent.rs @@ -77,7 +77,7 @@ fn test_transparent_wrapper() { #[cfg(feature = "extern_crate_alloc")] { use bytemuck::allocation::TransparentWrapperAlloc; - use std::{rc::Rc, sync::Arc}; + use std::rc::Rc; let a: Vec = vec![Foreign::default(); 2]; @@ -101,11 +101,16 @@ fn test_transparent_wrapper() { let i: Rc = Wrapper::peel_rc(h); assert_eq!(&*i, &0); - let j: Arc = Arc::new(Foreign::default()); + #[cfg(target_has_atomic = "ptr")] + { + use std::sync::Arc; - let k: Arc = Wrapper::wrap_arc(j); - assert_eq!(&*k, &0); - let l: Arc = Wrapper::peel_arc(k); - assert_eq!(&*l, &0); + let j: Arc = Arc::new(Foreign::default()); + + let k: Arc = Wrapper::wrap_arc(j); + assert_eq!(&*k, &0); + let l: Arc = Wrapper::peel_arc(k); + assert_eq!(&*l, &0); + } } }