Skip to content

Commit

Permalink
Update atomic_impl macros to have same input syntax in all cfgs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 12, 2022
1 parent 37faaf2 commit 0d79306
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
39 changes: 23 additions & 16 deletions serde/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,7 @@ where

#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
macro_rules! atomic_impl {
($($ty:ident)*) => {
($($ty:ident $size:expr)*) => {
$(
impl<'de> Deserialize<'de> for $ty {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand All @@ -2678,7 +2678,7 @@ macro_rules! atomic_impl {

#[cfg(all(feature = "std", not(no_target_has_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr),*) => {
($($ty:ident $size:expr)*) => {
$(
#[cfg(target_has_atomic = $size)]
impl<'de> Deserialize<'de> for $ty {
Expand All @@ -2695,28 +2695,35 @@ macro_rules! atomic_impl {

#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
atomic_impl! {
AtomicBool
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
AtomicBool "8"
AtomicI8 "8"
AtomicI16 "16"
AtomicI32 "32"
AtomicIsize "ptr"
AtomicU8 "8"
AtomicU16 "16"
AtomicU32 "32"
AtomicUsize "ptr"
}

#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
atomic_impl! {
AtomicI64 AtomicU64
AtomicI64 "64"
AtomicU64 "64"
}

#[cfg(all(feature = "std", not(no_target_has_atomic)))]
atomic_impl! {
AtomicBool "8",
AtomicI8 "8",
AtomicI16 "16",
AtomicI32 "32",
AtomicI64 "64",
AtomicIsize "ptr",
AtomicU8 "8",
AtomicU16 "16",
AtomicU32 "32",
AtomicU64 "64",
AtomicBool "8"
AtomicI8 "8"
AtomicI16 "16"
AtomicI32 "32"
AtomicI64 "64"
AtomicIsize "ptr"
AtomicU8 "8"
AtomicU16 "16"
AtomicU32 "32"
AtomicU64 "64"
AtomicUsize "ptr"
}

Expand Down
39 changes: 23 additions & 16 deletions serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ where

#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
macro_rules! atomic_impl {
($($ty:ident)*) => {
($($ty:ident $size:expr)*) => {
$(
impl Serialize for $ty {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -964,7 +964,7 @@ macro_rules! atomic_impl {

#[cfg(all(feature = "std", not(no_target_has_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr),*) => {
($($ty:ident $size:expr)*) => {
$(
#[cfg(target_has_atomic = $size)]
impl Serialize for $ty {
Expand All @@ -982,27 +982,34 @@ macro_rules! atomic_impl {

#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
atomic_impl! {
AtomicBool
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
AtomicBool "8"
AtomicI8 "8"
AtomicI16 "16"
AtomicI32 "32"
AtomicIsize "ptr"
AtomicU8 "8"
AtomicU16 "16"
AtomicU32 "32"
AtomicUsize "ptr"
}

#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
atomic_impl! {
AtomicI64 AtomicU64
AtomicI64 "64"
AtomicU64 "64"
}

#[cfg(all(feature = "std", not(no_target_has_atomic)))]
atomic_impl! {
AtomicBool "8",
AtomicI8 "8",
AtomicI16 "16",
AtomicI32 "32",
AtomicI64 "64",
AtomicIsize "ptr",
AtomicU8 "8",
AtomicU16 "16",
AtomicU32 "32",
AtomicU64 "64",
AtomicBool "8"
AtomicI8 "8"
AtomicI16 "16"
AtomicI32 "32"
AtomicI64 "64"
AtomicIsize "ptr"
AtomicU8 "8"
AtomicU16 "16"
AtomicU32 "32"
AtomicU64 "64"
AtomicUsize "ptr"
}

0 comments on commit 0d79306

Please sign in to comment.