From 005cb84593e73cb3ba263232cc5f09b77859ec5b Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 11 Aug 2024 20:00:02 +0500 Subject: [PATCH] Fail with an understandable message is number of fields for serialization is too many --- serde_derive/src/ser.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index 7d89d2212..a0291aff7 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -289,7 +289,13 @@ fn serialize_tuple_struct( } fn serialize_struct(params: &Parameters, fields: &[Field], cattrs: &attr::Container) -> Fragment { - assert!(fields.len() as u64 <= u64::from(u32::MAX)); + assert!( + fields.len() as u64 <= u64::from(u32::MAX), + "too many fields in {}: {}, maximum supported count is {}", + cattrs.name().serialize_name(), + fields.len(), + u32::MAX + ); if cattrs.has_flatten() { serialize_struct_as_map(params, fields, cattrs)