diff --git a/serde_with/src/content/ser.rs b/serde_with/src/content/ser.rs index c7570545..bf4e332b 100644 --- a/serde_with/src/content/ser.rs +++ b/serde_with/src/content/ser.rs @@ -253,9 +253,9 @@ where Ok(Content::None) } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Ok(Content::Some(Box::new(value.serialize(self)?))) } @@ -277,13 +277,9 @@ where Ok(Content::UnitVariant(name, variant_index, variant)) } - fn serialize_newtype_struct( - self, - name: &'static str, - value: &T, - ) -> Result + fn serialize_newtype_struct(self, name: &'static str, value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Ok(Content::NewtypeStruct( name, @@ -291,7 +287,7 @@ where )) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, name: &'static str, variant_index: u32, @@ -299,7 +295,7 @@ where value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Ok(Content::NewtypeVariant( name, @@ -404,9 +400,9 @@ where type Ok = Content; type Error = E; - fn serialize_element(&mut self, value: &T) -> Result<(), E> + fn serialize_element(&mut self, value: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let value = value.serialize(ContentSerializer::::new(self.is_human_readable))?; self.elements.push(value); @@ -431,9 +427,9 @@ where type Ok = Content; type Error = E; - fn serialize_element(&mut self, value: &T) -> Result<(), E> + fn serialize_element(&mut self, value: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let value = value.serialize(ContentSerializer::::new(self.is_human_readable))?; self.elements.push(value); @@ -459,9 +455,9 @@ where type Ok = Content; type Error = E; - fn serialize_field(&mut self, value: &T) -> Result<(), E> + fn serialize_field(&mut self, value: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let value = value.serialize(ContentSerializer::::new(self.is_human_readable))?; self.fields.push(value); @@ -489,9 +485,9 @@ where type Ok = Content; type Error = E; - fn serialize_field(&mut self, value: &T) -> Result<(), E> + fn serialize_field(&mut self, value: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let value = value.serialize(ContentSerializer::::new(self.is_human_readable))?; self.fields.push(value); @@ -522,18 +518,18 @@ where type Ok = Content; type Error = E; - fn serialize_key(&mut self, key: &T) -> Result<(), E> + fn serialize_key(&mut self, key: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let key = key.serialize(ContentSerializer::::new(self.is_human_readable))?; self.key = Some(key); Ok(()) } - fn serialize_value(&mut self, value: &T) -> Result<(), E> + fn serialize_value(&mut self, value: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let key = self .key @@ -548,10 +544,10 @@ where Ok(Content::Map(self.entries)) } - fn serialize_entry(&mut self, key: &K, value: &V) -> Result<(), E> + fn serialize_entry(&mut self, key: &K, value: &V) -> Result<(), E> where - K: Serialize, - V: Serialize, + K: Serialize + ?Sized, + V: Serialize + ?Sized, { let key = key.serialize(ContentSerializer::::new(self.is_human_readable))?; let value = value.serialize(ContentSerializer::::new(self.is_human_readable))?; @@ -574,9 +570,9 @@ where type Ok = Content; type Error = E; - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), E> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let value = value.serialize(ContentSerializer::::new(self.is_human_readable))?; self.fields.push((key, value)); @@ -604,9 +600,9 @@ where type Ok = Content; type Error = E; - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), E> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), E> where - T: Serialize, + T: Serialize + ?Sized, { let value = value.serialize(ContentSerializer::::new(self.is_human_readable))?; self.fields.push((key, value)); diff --git a/serde_with/src/enum_map.rs b/serde_with/src/enum_map.rs index 58471d07..04b98712 100644 --- a/serde_with/src/enum_map.rs +++ b/serde_with/src/enum_map.rs @@ -302,9 +302,9 @@ where Err(SerError::custom("wrong type for EnumMap")) } - fn serialize_some(self, _value: &T) -> Result + fn serialize_some(self, _value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for EnumMap")) } @@ -326,18 +326,18 @@ where Err(SerError::custom("wrong type for EnumMap")) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for EnumMap")) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -345,7 +345,7 @@ where _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for EnumMap")) } @@ -422,9 +422,9 @@ where type Ok = M::Ok; type Error = M::Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { value.serialize(EnumAsMapElementSerializer { delegate: &mut self.delegate, @@ -530,9 +530,9 @@ where Err(SerError::custom("wrong type for EnumMap")) } - fn serialize_some(self, _value: &T) -> Result + fn serialize_some(self, _value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for EnumMap")) } @@ -555,18 +555,18 @@ where Ok(()) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for EnumMap")) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -574,7 +574,7 @@ where value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { self.delegate.serialize_entry(variant, value)?; Ok(()) @@ -657,13 +657,9 @@ where type Error = M::Error; - fn serialize_field( - &mut self, - key: &'static str, - value: &T, - ) -> Result<(), Self::Error> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { // Serialize to a Content type first let value: Content = value.serialize(ContentSerializer::new(self.is_human_readable))?; @@ -686,9 +682,9 @@ where type Error = M::Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { // Serialize to a Content type first let value: Content = value.serialize(ContentSerializer::new(self.is_human_readable))?; diff --git a/serde_with/src/key_value_map.rs b/serde_with/src/key_value_map.rs index ce0b883d..9418b9eb 100644 --- a/serde_with/src/key_value_map.rs +++ b/serde_with/src/key_value_map.rs @@ -307,9 +307,9 @@ where Err(SerError::custom("wrong type for KeyValueMap")) } - fn serialize_some(self, _value: &T) -> Result + fn serialize_some(self, _value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for KeyValueMap")) } @@ -331,18 +331,18 @@ where Err(SerError::custom("wrong type for KeyValueMap")) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for KeyValueMap")) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -350,7 +350,7 @@ where _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for KeyValueMap")) } @@ -428,9 +428,9 @@ where type Ok = M::Ok; type Error = M::Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { value.serialize(ElementAsKeyValueSerializer { delegate: &mut self.delegate, @@ -536,9 +536,9 @@ where Err(SerError::custom("wrong type for KeyValueMap")) } - fn serialize_some(self, _value: &T) -> Result + fn serialize_some(self, _value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for KeyValueMap")) } @@ -560,18 +560,18 @@ where Err(SerError::custom("wrong type for KeyValueMap")) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for KeyValueMap")) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -579,7 +579,7 @@ where _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(SerError::custom("wrong type for KeyValueMap")) } @@ -679,9 +679,9 @@ where type Ok = (); type Error = M::Error; - fn serialize_element(&mut self, element: &T) -> Result<(), Self::Error> + fn serialize_element(&mut self, element: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { let element: SerContent = element.serialize(ContentSerializer::new(self.is_human_readable))?; @@ -720,9 +720,9 @@ where type Ok = (); type Error = M::Error; - fn serialize_element(&mut self, element: &T) -> Result<(), Self::Error> + fn serialize_element(&mut self, element: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { let element: SerContent = element.serialize(ContentSerializer::new(self.is_human_readable))?; @@ -762,9 +762,9 @@ where type Ok = (); type Error = M::Error; - fn serialize_field(&mut self, field: &T) -> Result<(), Self::Error> + fn serialize_field(&mut self, field: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { let field: SerContent = field.serialize(ContentSerializer::new(self.is_human_readable))?; if self.key.is_none() { @@ -804,9 +804,9 @@ where type Ok = (); type Error = M::Error; - fn serialize_key(&mut self, key: &T) -> Result<(), Self::Error> + fn serialize_key(&mut self, key: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { let key: SerContent = key.serialize(ContentSerializer::new(self.is_human_readable))?; if key.as_str() == Some(MAP_KEY_IDENTIFIER) { @@ -817,9 +817,9 @@ where Ok(()) } - fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { let value: SerContent = value.serialize(ContentSerializer::new(self.is_human_readable))?; @@ -865,13 +865,9 @@ where type Ok = (); type Error = M::Error; - fn serialize_field( - &mut self, - key: &'static str, - value: &T, - ) -> Result<(), Self::Error> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error> where - T: Serialize, + T: Serialize + ?Sized, { // Serialize to a Content type first let value: SerContent = value.serialize(ContentSerializer::new(self.is_human_readable))?; diff --git a/serde_with/src/lib.rs b/serde_with/src/lib.rs index 60562b2b..0546ded6 100644 --- a/serde_with/src/lib.rs +++ b/serde_with/src/lib.rs @@ -1,15 +1,19 @@ -#![doc(test(attr(forbid(unsafe_code))))] -#![doc(test(attr(deny( - missing_debug_implementations, - rust_2018_idioms, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - warnings, -))))] -#![doc(test(attr(warn(rust_2018_idioms))))] +#![doc(test(attr( + // Problematic handling for foreign From impls in tests + // https://github.com/rust-lang/rust/issues/121621 + allow(unknown_lints, non_local_definitions), + deny( + missing_debug_implementations, + rust_2018_idioms, + trivial_casts, + trivial_numeric_casts, + unused_extern_crates, + unused_import_braces, + unused_qualifications, + warnings, + ), + forbid(unsafe_code), +)))] // Not needed for 2018 edition and conflicts with `rust_2018_idioms` #![doc(test(no_crate_inject))] #![doc(html_root_url = "https://docs.rs/serde_with/3.6.1/")] diff --git a/serde_with/tests/serde_as/map_tuple_list.rs b/serde_with/tests/serde_as/map_tuple_list.rs index 59b00d61..f0957b81 100644 --- a/serde_with/tests/serde_as/map_tuple_list.rs +++ b/serde_with/tests/serde_as/map_tuple_list.rs @@ -353,6 +353,8 @@ fn test_map_as_tuple_with_nested_complex_type() { ); } +// Problematic handling around fundamental types: https://github.com/rust-lang/rust/issues/121621 +#[allow(unknown_lints, non_local_definitions)] #[test] fn test_map_as_tuple_list_works_with_serializer_that_needs_length_to_serialize_sequence() { use serde::{ diff --git a/serde_with_macros/src/lib.rs b/serde_with_macros/src/lib.rs index 01b19553..bed1a8a1 100644 --- a/serde_with_macros/src/lib.rs +++ b/serde_with_macros/src/lib.rs @@ -2,18 +2,22 @@ // https://github.com/rust-lang/cargo/issues/13157 #![forbid(unsafe_code)] #![warn(missing_copy_implementations, missing_debug_implementations)] -#![doc(test(attr(forbid(unsafe_code))))] -#![doc(test(attr(deny( - missing_debug_implementations, - rust_2018_idioms, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - warnings, -))))] -#![doc(test(attr(warn(rust_2018_idioms))))] +#![doc(test(attr( + // Problematic handling for foreign From impls in tests + // https://github.com/rust-lang/rust/issues/121621 + allow(unknown_lints, non_local_definitions), + deny( + missing_debug_implementations, + rust_2018_idioms, + trivial_casts, + trivial_numeric_casts, + unused_extern_crates, + unused_import_braces, + unused_qualifications, + warnings, + ), + forbid(unsafe_code), +)))] // Not needed for 2018 edition and conflicts with `rust_2018_idioms` #![doc(test(no_crate_inject))] #![doc(html_root_url = "https://docs.rs/serde_with_macros/3.6.1/")]