Relocate cfg attrs into deref_impl

This commit is contained in:
David Tolnay 2023-11-06 11:13:28 -08:00
parent 64f949b37b
commit 05c2509d07
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -475,10 +475,10 @@ map_impl! {
macro_rules! deref_impl { macro_rules! deref_impl {
( (
$(#[doc = $doc:tt])* $(#[$attr:meta])*
<$($desc:tt)+ <$($desc:tt)+
) => { ) => {
$(#[doc = $doc])* $(#[$attr])*
impl <$($desc)+ { impl <$($desc)+ {
#[inline] #[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@ -491,13 +491,19 @@ macro_rules! deref_impl {
}; };
} }
deref_impl!(<'a, T: ?Sized> Serialize for &'a T where T: Serialize); deref_impl! {
deref_impl!(<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize); <'a, T: ?Sized> Serialize for &'a T where T: Serialize
}
#[cfg(any(feature = "std", feature = "alloc"))] deref_impl! {
deref_impl!(<T: ?Sized> Serialize for Box<T> where T: Serialize); <'a, T: ?Sized> Serialize for &'a mut T where T: Serialize
}
deref_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
<T: ?Sized> Serialize for Box<T> where T: Serialize
}
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
deref_impl! { deref_impl! {
/// This impl requires the [`"rc"`] Cargo feature of Serde. /// This impl requires the [`"rc"`] Cargo feature of Serde.
/// ///
@ -507,10 +513,10 @@ deref_impl! {
/// repeated data. /// repeated data.
/// ///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
<T: ?Sized> Serialize for Rc<T> where T: Serialize <T: ?Sized> Serialize for Rc<T> where T: Serialize
} }
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
deref_impl! { deref_impl! {
/// This impl requires the [`"rc"`] Cargo feature of Serde. /// This impl requires the [`"rc"`] Cargo feature of Serde.
/// ///
@ -520,11 +526,14 @@ deref_impl! {
/// repeated data. /// repeated data.
/// ///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
<T: ?Sized> Serialize for Arc<T> where T: Serialize <T: ?Sized> Serialize for Arc<T> where T: Serialize
} }
#[cfg(any(feature = "std", feature = "alloc"))] deref_impl! {
deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned); #[cfg(any(feature = "std", feature = "alloc"))]
<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////