gate atomic serde on rust 1.34 or higher

This commit is contained in:
James Brown 2019-07-12 13:44:42 -07:00
parent de709e72a8
commit 4e5f63ff45
4 changed files with 30 additions and 27 deletions

View File

@ -68,6 +68,10 @@ fn main() {
if minor >= 28 { if minor >= 28 {
println!("cargo:rustc-cfg=num_nonzero"); println!("cargo:rustc-cfg=num_nonzero");
} }
if minor >= 34 {
println!("cargo:rustc-cfg=std_integer_atomics");
}
} }
fn rustc_minor_version() -> Option<u32> { fn rustc_minor_version() -> Option<u32> {

View File

@ -2544,11 +2544,11 @@ where
} }
} }
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
use std::sync::atomic; use std::sync::atomic;
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
macro_rules! atomic_impl { macro_rules! atomic_impl {
($ty:path, $primitive:ident) => { ($ty:path, $primitive:ident) => {
impl<'de> Deserialize<'de> for $ty 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); atomic_impl!(atomic::AtomicBool, bool);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI8, i8); atomic_impl!(atomic::AtomicI8, i8);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI16, i16); atomic_impl!(atomic::AtomicI16, i16);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI32, i32); atomic_impl!(atomic::AtomicI32, i32);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI64, i64); atomic_impl!(atomic::AtomicI64, i64);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicIsize, isize); atomic_impl!(atomic::AtomicIsize, isize);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU8, u8); atomic_impl!(atomic::AtomicU8, u8);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU16, u16); atomic_impl!(atomic::AtomicU16, u16);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU32, u32); atomic_impl!(atomic::AtomicU32, u32);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU64, u64); atomic_impl!(atomic::AtomicU64, u64);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicUsize, usize); atomic_impl!(atomic::AtomicUsize, usize);

View File

@ -841,10 +841,10 @@ where
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
use std::sync::atomic; use std::sync::atomic;
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
macro_rules! atomic_impl { macro_rules! atomic_impl {
($ty:path, $method:ident $($cast:tt)*) => { ($ty:path, $method:ident $($cast:tt)*) => {
impl Serialize for $ty { 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); atomic_impl!(atomic::AtomicBool, serialize_bool);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI8, serialize_i8); atomic_impl!(atomic::AtomicI8, serialize_i8);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI16, serialize_i16); atomic_impl!(atomic::AtomicI16, serialize_i16);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI32, serialize_i32); atomic_impl!(atomic::AtomicI32, serialize_i32);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicI64, serialize_i64); atomic_impl!(atomic::AtomicI64, serialize_i64);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicIsize, serialize_i64 as i64); atomic_impl!(atomic::AtomicIsize, serialize_i64 as i64);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU8, serialize_u8); atomic_impl!(atomic::AtomicU8, serialize_u8);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU16, serialize_u16); atomic_impl!(atomic::AtomicU16, serialize_u16);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU32, serialize_u32); atomic_impl!(atomic::AtomicU32, serialize_u32);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicU64, serialize_u64); atomic_impl!(atomic::AtomicU64, serialize_u64);
#[cfg(feature = "std")] #[cfg(all(feature="std", std_integer_atomics))]
atomic_impl!(atomic::AtomicUsize, serialize_u64 as u64); atomic_impl!(atomic::AtomicUsize, serialize_u64 as u64);

View File

@ -1141,7 +1141,6 @@ fn test_never_type() {
); );
} }
macro_rules! assert_de_tokens_atomic { macro_rules! assert_de_tokens_atomic {
($ty:ty, $val:expr, $tokens:expr) => { ($ty:ty, $val:expr, $tokens:expr) => {
let mut de = serde_test::Deserializer::new($tokens); let mut de = serde_test::Deserializer::new($tokens);