Skip to content

Commit

Permalink
Remove some Serialize trait bounds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonasbb committed Dec 3, 2022
1 parent 7766103 commit cc128fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions serde/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +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
Expand Down
20 changes: 19 additions & 1 deletion serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
Expand Down

0 comments on commit cc128fe

Please sign in to comment.