From 1c28ab6fd118c043bc82c2a1a26048dbd7fab31e Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sat, 3 Dec 2022 16:00:43 +0100 Subject: [PATCH] Remove some Serialize trait bounds Containers for the most part do not have any trait requirements for iterating over them. So these bounds are unnecessary when Serializing only. This relaxation is part of Rust 1.34 --- serde/build.rs | 2 +- serde/src/ser/impls.rs | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/serde/build.rs b/serde/build.rs index a1103b520a..9da0660b84 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -89,7 +89,7 @@ fn main() { println!("cargo:rustc-cfg=no_core_try_from"); println!("cargo:rustc-cfg=no_num_nonzero_signed"); println!("cargo:rustc-cfg=no_systemtime_checked_add"); - } + println!("cargo:rustc-cfg=no_relaxed_trait_bounds"); // Whitelist of archs that support std::sync::atomic module. Ideally we // would use #[cfg(target_has_atomic = "...")] but it is not stable yet. diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index ccef4d2916..1f1ad1711b 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -182,7 +182,25 @@ where } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))] +macro_rules! seq_impl { + ($ty:ident < T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)* >) => { + impl Serialize for $ty + where + T: Serialize, + { + #[inline] + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.collect_seq(self) + } + } + } +} + +#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))] macro_rules! seq_impl { ($ty:ident < T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)* >) => { impl Serialize for $ty