diff --git a/serde/build.rs b/serde/build.rs index e27e2f34..ae0f9869 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -68,6 +68,10 @@ fn main() { if minor >= 28 { println!("cargo:rustc-cfg=num_nonzero"); } + + if minor >= 34 { + println!("cargo:rustc-cfg=std_integer_atomics"); + } } fn rustc_minor_version() -> Option { diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 300abe34..0a28c43e 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -2544,11 +2544,11 @@ where } } -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] use std::sync::atomic; -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] macro_rules! atomic_impl { ($ty:path, $primitive:ident) => { impl<'de> Deserialize<'de> for $ty @@ -2564,35 +2564,35 @@ macro_rules! atomic_impl { } } -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicBool, bool); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI8, i8); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI16, i16); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI32, i32); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI64, i64); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicIsize, isize); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU8, u8); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU16, u16); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU32, u32); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU64, u64); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicUsize, usize); diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 745f69d5..59b54117 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -841,10 +841,10 @@ where } //////////////////////////////////////////////////////////////////////////////// -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] use std::sync::atomic; -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] macro_rules! atomic_impl { ($ty:path, $method:ident $($cast:tt)*) => { impl Serialize for $ty { @@ -859,35 +859,35 @@ macro_rules! atomic_impl { } } -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicBool, serialize_bool); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI8, serialize_i8); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI16, serialize_i16); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI32, serialize_i32); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicI64, serialize_i64); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicIsize, serialize_i64 as i64); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU8, serialize_u8); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU16, serialize_u16); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU32, serialize_u32); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicU64, serialize_u64); -#[cfg(feature = "std")] +#[cfg(all(feature="std", std_integer_atomics))] atomic_impl!(atomic::AtomicUsize, serialize_u64 as u64); diff --git a/test_suite/tests/test_de.rs b/test_suite/tests/test_de.rs index b96f1739..c970b8de 100644 --- a/test_suite/tests/test_de.rs +++ b/test_suite/tests/test_de.rs @@ -1141,7 +1141,6 @@ fn test_never_type() { ); } - macro_rules! assert_de_tokens_atomic { ($ty:ty, $val:expr, $tokens:expr) => { let mut de = serde_test::Deserializer::new($tokens);