diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 51444326..ebdcfd58 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -878,9 +878,9 @@ impl<'de, T: ?Sized> Deserialize<'de> for PhantomData { //////////////////////////////////////////////////////////////////////////////// -#[cfg(any(feature = "std", feature = "alloc"))] macro_rules! seq_impl { ( + $(#[$attr:meta])* $ty:ident , $access:ident, $clear:expr, @@ -888,6 +888,7 @@ macro_rules! seq_impl { $reserve:expr, $insert:expr ) => { + $(#[$attr])* impl<'de, T $(, $typaram)*> Deserialize<'de> for $ty where T: Deserialize<'de> $(+ $tbound1 $(+ $tbound2)*)*, @@ -975,8 +976,8 @@ macro_rules! seq_impl { #[cfg(any(feature = "std", feature = "alloc"))] fn nop_reserve(_seq: T, _n: usize) {} -#[cfg(any(feature = "std", feature = "alloc"))] seq_impl!( + #[cfg(any(feature = "std", feature = "alloc"))] BinaryHeap, seq, BinaryHeap::clear, @@ -985,8 +986,8 @@ seq_impl!( BinaryHeap::push ); -#[cfg(any(feature = "std", feature = "alloc"))] seq_impl!( + #[cfg(any(feature = "std", feature = "alloc"))] BTreeSet, seq, BTreeSet::clear, @@ -995,8 +996,8 @@ seq_impl!( BTreeSet::insert ); -#[cfg(any(feature = "std", feature = "alloc"))] seq_impl!( + #[cfg(any(feature = "std", feature = "alloc"))] LinkedList, seq, LinkedList::clear, @@ -1005,8 +1006,8 @@ seq_impl!( LinkedList::push_back ); -#[cfg(feature = "std")] seq_impl!( + #[cfg(feature = "std")] HashSet, seq, HashSet::clear, @@ -1015,8 +1016,8 @@ seq_impl!( HashSet::insert ); -#[cfg(any(feature = "std", feature = "alloc"))] seq_impl!( + #[cfg(any(feature = "std", feature = "alloc"))] VecDeque, seq, VecDeque::clear, @@ -1373,13 +1374,14 @@ tuple_impls! { //////////////////////////////////////////////////////////////////////////////// -#[cfg(any(feature = "std", feature = "alloc"))] macro_rules! map_impl { ( + $(#[$attr:meta])* $ty:ident , $access:ident, - $with_capacity:expr + $with_capacity:expr, ) => { + $(#[$attr])* impl<'de, K, V $(, $typaram)*> Deserialize<'de> for $ty where K: Deserialize<'de> $(+ $kbound1 $(+ $kbound2)*)*, @@ -1428,15 +1430,19 @@ macro_rules! map_impl { } } -#[cfg(any(feature = "std", feature = "alloc"))] -map_impl!(BTreeMap, map, BTreeMap::new()); +map_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + BTreeMap, + map, + BTreeMap::new(), +} -#[cfg(feature = "std")] -map_impl!( +map_impl! { + #[cfg(feature = "std")] HashMap, map, - HashMap::with_capacity_and_hasher(size_hint::cautious::<(K, V)>(map.size_hint()), S::default()) -); + HashMap::with_capacity_and_hasher(size_hint::cautious::<(K, V)>(map.size_hint()), S::default()), +} //////////////////////////////////////////////////////////////////////////////// diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 39acba31..75f84b24 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -179,9 +179,13 @@ where } } -#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))] +#[cfg(not(no_relaxed_trait_bounds))] macro_rules! seq_impl { - ($ty:ident ) => { + ( + $(#[$attr:meta])* + $ty:ident + ) => { + $(#[$attr])* impl Serialize for $ty where T: Serialize, @@ -197,9 +201,13 @@ macro_rules! seq_impl { } } -#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))] +#[cfg(no_relaxed_trait_bounds)] macro_rules! seq_impl { - ($ty:ident ) => { + ( + $(#[$attr:meta])* + $ty:ident + ) => { + $(#[$attr])* impl Serialize for $ty where T: Serialize $(+ $tbound1 $(+ $tbound2)*)*, @@ -216,23 +224,35 @@ macro_rules! seq_impl { } } -#[cfg(any(feature = "std", feature = "alloc"))] -seq_impl!(BinaryHeap); +seq_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + BinaryHeap +} -#[cfg(any(feature = "std", feature = "alloc"))] -seq_impl!(BTreeSet); +seq_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + BTreeSet +} -#[cfg(feature = "std")] -seq_impl!(HashSet); +seq_impl! { + #[cfg(feature = "std")] + HashSet +} -#[cfg(any(feature = "std", feature = "alloc"))] -seq_impl!(LinkedList); +seq_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + LinkedList +} -#[cfg(any(feature = "std", feature = "alloc"))] -seq_impl!(Vec); +seq_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + Vec +} -#[cfg(any(feature = "std", feature = "alloc"))] -seq_impl!(VecDeque); +seq_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + VecDeque +} //////////////////////////////////////////////////////////////////////////////// @@ -394,9 +414,13 @@ tuple_impls! { //////////////////////////////////////////////////////////////////////////////// -#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))] +#[cfg(not(no_relaxed_trait_bounds))] macro_rules! map_impl { - ($ty:ident ) => { + ( + $(#[$attr:meta])* + $ty:ident + ) => { + $(#[$attr])* impl Serialize for $ty where K: Serialize, @@ -413,9 +437,13 @@ macro_rules! map_impl { } } -#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))] +#[cfg(no_relaxed_trait_bounds)] macro_rules! map_impl { - ($ty:ident ) => { + ( + $(#[$attr:meta])* + $ty:ident + ) => { + $(#[$attr])* impl Serialize for $ty where K: Serialize $(+ $kbound1 $(+ $kbound2)*)*, @@ -433,11 +461,15 @@ macro_rules! map_impl { } } -#[cfg(any(feature = "std", feature = "alloc"))] -map_impl!(BTreeMap); +map_impl! { + #[cfg(any(feature = "std", feature = "alloc"))] + BTreeMap +} -#[cfg(feature = "std")] -map_impl!(HashMap); +map_impl! { + #[cfg(feature = "std")] + HashMap +} ////////////////////////////////////////////////////////////////////////////////