From 7440e56c5383724ff4d24fb77778d7c1a66e07d1 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 11 Dec 2022 16:09:26 -0800 Subject: [PATCH] Deduplicate atomic_impl macro implementations --- serde/src/de/impls.rs | 20 ++------------------ serde/src/ser/impls.rs | 21 ++------------------- 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index b2311e1dc..9621dcc43 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -2660,27 +2660,11 @@ where } } -#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))] -macro_rules! atomic_impl { - ($($ty:ident $size:expr)*) => { - $( - impl<'de> Deserialize<'de> for $ty { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - Deserialize::deserialize(deserializer).map(Self::new) - } - } - )* - }; -} - -#[cfg(all(feature = "std", not(no_target_has_atomic)))] +#[cfg(all(feature = "std", not(no_std_atomic)))] macro_rules! atomic_impl { ($($ty:ident $size:expr)*) => { $( - #[cfg(target_has_atomic = $size)] + #[cfg(any(no_target_has_atomic, target_has_atomic = $size))] impl<'de> Deserialize<'de> for $ty { fn deserialize(deserializer: D) -> Result where diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 4698827be..81c566959 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -945,28 +945,11 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))] -macro_rules! atomic_impl { - ($($ty:ident $size:expr)*) => { - $( - impl Serialize for $ty { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - // Matches the atomic ordering used in libcore for the Debug impl - self.load(Ordering::Relaxed).serialize(serializer) - } - } - )* - } -} - -#[cfg(all(feature = "std", not(no_target_has_atomic)))] +#[cfg(all(feature = "std", not(no_std_atomic)))] macro_rules! atomic_impl { ($($ty:ident $size:expr)*) => { $( - #[cfg(target_has_atomic = $size)] + #[cfg(any(no_target_has_atomic, target_has_atomic = $size))] impl Serialize for $ty { fn serialize(&self, serializer: S) -> Result where