From 7eef906a43df1c85940c83e1cda9cefb2a010883 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 2 May 2024 08:48:06 -0500 Subject: [PATCH] style: Address warnings --- crates/toml/src/map.rs | 24 ++--- crates/toml/src/ser.rs | 104 +++++++++------------ crates/toml/src/value.rs | 113 ++++++++++------------- crates/toml/tests/decoder.rs | 1 + crates/toml/tests/encoder.rs | 1 + crates/toml/tests/testsuite/serde.rs | 2 +- crates/toml_datetime/src/datetime.rs | 4 +- crates/toml_edit/src/de/mod.rs | 1 - crates/toml_edit/src/de/table.rs | 8 +- crates/toml_edit/src/de/value.rs | 6 +- crates/toml_edit/src/item.rs | 4 +- crates/toml_edit/src/parser/value.rs | 25 +++-- crates/toml_edit/src/ser/array.rs | 16 ++-- crates/toml_edit/src/ser/key.rs | 12 +-- crates/toml_edit/src/ser/map.rs | 76 +++++++-------- crates/toml_edit/src/ser/mod.rs | 16 ++-- crates/toml_edit/src/ser/value.rs | 12 +-- crates/toml_edit/tests/testsuite/edit.rs | 14 --- 18 files changed, 193 insertions(+), 246 deletions(-) diff --git a/crates/toml/src/map.rs b/crates/toml/src/map.rs index 26e77160..f7d5c38f 100644 --- a/crates/toml/src/map.rs +++ b/crates/toml/src/map.rs @@ -78,10 +78,10 @@ impl Map { /// The key may be any borrowed form of the map's key type, but the ordering /// on the borrowed form *must* match the ordering on the key type. #[inline] - pub fn get(&self, key: &Q) -> Option<&Value> + pub fn get(&self, key: &Q) -> Option<&Value> where String: Borrow, - Q: Ord + Eq + Hash, + Q: Ord + Eq + Hash + ?Sized, { self.map.get(key) } @@ -91,10 +91,10 @@ impl Map { /// The key may be any borrowed form of the map's key type, but the ordering /// on the borrowed form *must* match the ordering on the key type. #[inline] - pub fn contains_key(&self, key: &Q) -> bool + pub fn contains_key(&self, key: &Q) -> bool where String: Borrow, - Q: Ord + Eq + Hash, + Q: Ord + Eq + Hash + ?Sized, { self.map.contains_key(key) } @@ -104,10 +104,10 @@ impl Map { /// The key may be any borrowed form of the map's key type, but the ordering /// on the borrowed form *must* match the ordering on the key type. #[inline] - pub fn get_mut(&mut self, key: &Q) -> Option<&mut Value> + pub fn get_mut(&mut self, key: &Q) -> Option<&mut Value> where String: Borrow, - Q: Ord + Eq + Hash, + Q: Ord + Eq + Hash + ?Sized, { self.map.get_mut(key) } @@ -130,10 +130,10 @@ impl Map { /// The key may be any borrowed form of the map's key type, but the ordering /// on the borrowed form *must* match the ordering on the key type. #[inline] - pub fn remove(&mut self, key: &Q) -> Option + pub fn remove(&mut self, key: &Q) -> Option where String: Borrow, - Q: Ord + Eq + Hash, + Q: Ord + Eq + Hash + ?Sized, { self.map.remove(key) } @@ -241,10 +241,10 @@ impl PartialEq for Map { /// Access an element of this map. Panics if the given key is not present in the /// map. -impl<'a, Q: ?Sized> ops::Index<&'a Q> for Map +impl<'a, Q> ops::Index<&'a Q> for Map where String: Borrow, - Q: Ord + Eq + Hash, + Q: Ord + Eq + Hash + ?Sized, { type Output = Value; @@ -255,10 +255,10 @@ where /// Mutably access an element of this map. Panics if the given key is not /// present in the map. -impl<'a, Q: ?Sized> ops::IndexMut<&'a Q> for Map +impl<'a, Q> ops::IndexMut<&'a Q> for Map where String: Borrow, - Q: Ord + Eq + Hash, + Q: Ord + Eq + Hash + ?Sized, { fn index_mut(&mut self, index: &Q) -> &mut Value { self.map.get_mut(index).expect("no entry found for key") diff --git a/crates/toml/src/ser.rs b/crates/toml/src/ser.rs index fac18bb8..b64271a1 100644 --- a/crates/toml/src/ser.rs +++ b/crates/toml/src/ser.rs @@ -43,9 +43,9 @@ /// println!("{}", toml) /// ``` #[cfg(feature = "display")] -pub fn to_string(value: &T) -> Result +pub fn to_string(value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let mut output = String::new(); let serializer = Serializer::new(&mut output); @@ -63,9 +63,9 @@ where /// For greater customization, instead serialize to a /// [`toml_edit::DocumentMut`](https://docs.rs/toml_edit/latest/toml_edit/struct.DocumentMut.html). #[cfg(feature = "display")] -pub fn to_string_pretty(value: &T) -> Result +pub fn to_string_pretty(value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let mut output = String::new(); let serializer = Serializer::pretty(&mut output); @@ -301,9 +301,9 @@ impl<'d> serde::ser::Serializer for Serializer<'d> { ) } - fn serialize_some(self, v: &T) -> Result + fn serialize_some(self, v: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { write_document( self.dst, @@ -345,13 +345,9 @@ impl<'d> serde::ser::Serializer for Serializer<'d> { ) } - fn serialize_newtype_struct( - self, - name: &'static str, - v: &T, - ) -> Result + fn serialize_newtype_struct(self, name: &'static str, v: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { write_document( self.dst, @@ -360,7 +356,7 @@ impl<'d> serde::ser::Serializer for Serializer<'d> { ) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, name: &'static str, variant_index: u32, @@ -368,7 +364,7 @@ impl<'d> serde::ser::Serializer for Serializer<'d> { value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { write_document( self.dst, @@ -617,9 +613,9 @@ impl<'d> serde::ser::Serializer for ValueSerializer<'d> { ) } - fn serialize_some(self, v: &T) -> Result + fn serialize_some(self, v: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { write_value( self.dst, @@ -657,13 +653,9 @@ impl<'d> serde::ser::Serializer for ValueSerializer<'d> { ) } - fn serialize_newtype_struct( - self, - name: &'static str, - v: &T, - ) -> Result + fn serialize_newtype_struct(self, name: &'static str, v: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { write_value( self.dst, @@ -671,7 +663,7 @@ impl<'d> serde::ser::Serializer for ValueSerializer<'d> { ) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, name: &'static str, variant_index: u32, @@ -679,7 +671,7 @@ impl<'d> serde::ser::Serializer for ValueSerializer<'d> { value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { write_value( self.dst, @@ -785,9 +777,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_element(value).map_err(Error::wrap) } @@ -801,9 +793,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_element(value).map_err(Error::wrap) } @@ -817,9 +809,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_field(value).map_err(Error::wrap) } @@ -833,9 +825,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_field(value).map_err(Error::wrap) } @@ -869,16 +861,16 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> + fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_key(input).map_err(Error::wrap) } - fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_value(value).map_err(Error::wrap) } @@ -892,13 +884,9 @@ mod internal { type Ok = (); type Error = 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: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_field(key, value).map_err(Error::wrap) } @@ -954,9 +942,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_element(value).map_err(Error::wrap) } @@ -970,9 +958,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_element(value).map_err(Error::wrap) } @@ -986,9 +974,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_field(value).map_err(Error::wrap) } @@ -1002,9 +990,9 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_field(value).map_err(Error::wrap) } @@ -1036,16 +1024,16 @@ mod internal { type Ok = (); type Error = Error; - fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> + fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_key(input).map_err(Error::wrap) } - fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_value(value).map_err(Error::wrap) } @@ -1059,13 +1047,9 @@ mod internal { type Ok = (); type Error = 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: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.inner.serialize_field(key, value).map_err(Error::wrap) } diff --git a/crates/toml/src/value.rs b/crates/toml/src/value.rs index a059b3fb..c689b383 100644 --- a/crates/toml/src/value.rs +++ b/crates/toml/src/value.rs @@ -362,9 +362,9 @@ impl Index for String { } } -impl<'s, T: ?Sized> Index for &'s T +impl<'s, T> Index for &'s T where - T: Index, + T: Index + ?Sized, { fn index<'a>(&self, val: &'a Value) -> Option<&'a Value> { (**self).index(val) @@ -733,7 +733,7 @@ impl<'de> de::EnumAccess<'de> for MapDeserializer { fn variant_seed(mut self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error> where - V: serde::de::DeserializeSeed<'de>, + V: de::DeserializeSeed<'de>, { use de::Error; let (key, value) = match self.iter.next() { @@ -764,7 +764,7 @@ impl MapEnumDeserializer { } } -impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer { +impl<'de> de::VariantAccess<'de> for MapEnumDeserializer { type Error = crate::de::Error; fn unit_variant(self) -> Result<(), Self::Error> { @@ -793,20 +793,20 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer { fn newtype_variant_seed(self, seed: T) -> Result where - T: serde::de::DeserializeSeed<'de>, + T: de::DeserializeSeed<'de>, { seed.deserialize(self.value.into_deserializer()) } fn tuple_variant(self, len: usize, visitor: V) -> Result where - V: serde::de::Visitor<'de>, + V: de::Visitor<'de>, { use de::Error; match self.value { Value::Array(values) => { if values.len() == len { - serde::de::Deserializer::deserialize_seq(values.into_deserializer(), visitor) + de::Deserializer::deserialize_seq(values.into_deserializer(), visitor) } else { Err(Error::custom(format!("expected tuple with length {}", len))) } @@ -826,10 +826,7 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer { let tuple_values = tuple_values?; if tuple_values.len() == len { - serde::de::Deserializer::deserialize_seq( - tuple_values.into_deserializer(), - visitor, - ) + de::Deserializer::deserialize_seq(tuple_values.into_deserializer(), visitor) } else { Err(Error::custom(format!("expected tuple with length {}", len))) } @@ -847,9 +844,9 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer { visitor: V, ) -> Result where - V: serde::de::Visitor<'de>, + V: de::Visitor<'de>, { - serde::de::Deserializer::deserialize_struct( + de::Deserializer::deserialize_struct( self.value.into_deserializer(), "", // TODO: this should be the variant name fields, @@ -964,18 +961,18 @@ impl ser::Serializer for ValueSerializer { self.serialize_str(_variant) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, value: &T, ) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -983,7 +980,7 @@ impl ser::Serializer for ValueSerializer { value: &T, ) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { let value = value.serialize(ValueSerializer)?; let mut table = Table::new(); @@ -995,9 +992,9 @@ impl ser::Serializer for ValueSerializer { Err(crate::ser::Error::unsupported_none()) } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(self) } @@ -1145,18 +1142,18 @@ impl ser::Serializer for TableSerializer { Err(crate::ser::Error::unsupported_type(Some(name))) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, value: &T, ) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -1164,7 +1161,7 @@ impl ser::Serializer for TableSerializer { value: &T, ) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { let value = value.serialize(ValueSerializer)?; let mut table = Table::new(); @@ -1176,9 +1173,9 @@ impl ser::Serializer for TableSerializer { Err(crate::ser::Error::unsupported_none()) } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(self) } @@ -1243,9 +1240,9 @@ impl ser::SerializeSeq for ValueSerializeVec { type Ok = Value; type Error = crate::ser::Error; - fn serialize_element(&mut self, value: &T) -> Result<(), crate::ser::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { self.vec.push(Value::try_from(value)?); Ok(()) @@ -1260,9 +1257,9 @@ impl ser::SerializeTuple for ValueSerializeVec { type Ok = Value; type Error = crate::ser::Error; - fn serialize_element(&mut self, value: &T) -> Result<(), crate::ser::Error> + fn serialize_element(&mut self, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeSeq::serialize_element(self, value) } @@ -1276,9 +1273,9 @@ impl ser::SerializeTupleStruct for ValueSerializeVec { type Ok = Value; type Error = crate::ser::Error; - fn serialize_field(&mut self, value: &T) -> Result<(), crate::ser::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeSeq::serialize_element(self, value) } @@ -1292,9 +1289,9 @@ impl ser::SerializeTupleVariant for ValueSerializeVec { type Ok = Value; type Error = crate::ser::Error; - fn serialize_field(&mut self, value: &T) -> Result<(), crate::ser::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeSeq::serialize_element(self, value) } @@ -1313,9 +1310,9 @@ impl ser::SerializeMap for SerializeMap { type Ok = Table; type Error = crate::ser::Error; - fn serialize_key(&mut self, key: &T) -> Result<(), crate::ser::Error> + fn serialize_key(&mut self, key: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { match Value::try_from(key)? { Value::String(s) => self.next_key = Some(s), @@ -1324,9 +1321,9 @@ impl ser::SerializeMap for SerializeMap { Ok(()) } - fn serialize_value(&mut self, value: &T) -> Result<(), crate::ser::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { let key = self.next_key.take(); let key = key.expect("serialize_value called before serialize_key"); @@ -1351,13 +1348,9 @@ impl ser::SerializeStruct for SerializeMap { type Ok = Table; type Error = crate::ser::Error; - fn serialize_field( - &mut self, - key: &'static str, - value: &T, - ) -> Result<(), crate::ser::Error> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeMap::serialize_key(self, key)?; ser::SerializeMap::serialize_value(self, value) @@ -1376,16 +1369,16 @@ impl ser::SerializeMap for ValueSerializeMap { type Ok = Value; type Error = crate::ser::Error; - fn serialize_key(&mut self, key: &T) -> Result<(), crate::ser::Error> + fn serialize_key(&mut self, key: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { self.ser.serialize_key(key) } - fn serialize_value(&mut self, value: &T) -> Result<(), crate::ser::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { self.ser.serialize_value(value) } @@ -1399,13 +1392,9 @@ impl ser::SerializeStruct for ValueSerializeMap { type Ok = Value; type Error = crate::ser::Error; - fn serialize_field( - &mut self, - key: &'static str, - value: &T, - ) -> Result<(), crate::ser::Error> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), crate::ser::Error> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeMap::serialize_key(self, key)?; ser::SerializeMap::serialize_value(self, value) @@ -1496,40 +1485,40 @@ impl ValueSerializeVariant { } } -impl serde::ser::SerializeTupleVariant for ValueSerializeVariant { +impl ser::SerializeTupleVariant for ValueSerializeVariant { type Ok = Value; type Error = crate::ser::Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: ser::Serialize + ?Sized, { - serde::ser::SerializeSeq::serialize_element(&mut self.inner, value) + ser::SerializeSeq::serialize_element(&mut self.inner, value) } fn end(self) -> Result { - let inner = serde::ser::SerializeSeq::end(self.inner)?; + let inner = ser::SerializeSeq::end(self.inner)?; let mut table = Table::new(); table.insert(self.variant.to_owned(), inner); Ok(Value::Table(table)) } } -impl serde::ser::SerializeStructVariant for ValueSerializeVariant { +impl ser::SerializeStructVariant for ValueSerializeVariant { type Ok = Value; type Error = crate::ser::Error; #[inline] fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize + ?Sized, + T: ser::Serialize + ?Sized, { - serde::ser::SerializeStruct::serialize_field(&mut self.inner, key, value) + ser::SerializeStruct::serialize_field(&mut self.inner, key, value) } #[inline] fn end(self) -> Result { - let inner = serde::ser::SerializeStruct::end(self.inner)?; + let inner = ser::SerializeStruct::end(self.inner)?; let mut table = Table::new(); table.insert(self.variant.to_owned(), inner); Ok(Value::Table(table)) diff --git a/crates/toml/tests/decoder.rs b/crates/toml/tests/decoder.rs index a963f95b..399c1ddb 100644 --- a/crates/toml/tests/decoder.rs +++ b/crates/toml/tests/decoder.rs @@ -1,4 +1,5 @@ #![cfg(all(feature = "parse", feature = "display"))] +#![allow(dead_code)] #[derive(Copy, Clone)] pub(crate) struct Decoder; diff --git a/crates/toml/tests/encoder.rs b/crates/toml/tests/encoder.rs index 972aac6d..2f7ceae8 100644 --- a/crates/toml/tests/encoder.rs +++ b/crates/toml/tests/encoder.rs @@ -1,4 +1,5 @@ #![cfg(all(feature = "parse", feature = "display"))] +#![allow(dead_code)] #[derive(Copy, Clone)] pub(crate) struct Encoder; diff --git a/crates/toml/tests/testsuite/serde.rs b/crates/toml/tests/testsuite/serde.rs index 8c9092c5..52d0113e 100644 --- a/crates/toml/tests/testsuite/serde.rs +++ b/crates/toml/tests/testsuite/serde.rs @@ -131,7 +131,7 @@ fn application_decode_error() { struct Range10(usize); impl<'de> Deserialize<'de> for Range10 { fn deserialize>(d: D) -> Result { - let x: usize = serde::Deserialize::deserialize(d)?; + let x: usize = Deserialize::deserialize(d)?; if x > 10 { Err(serde::de::Error::custom("more than 10")) } else { diff --git a/crates/toml_datetime/src/datetime.rs b/crates/toml_datetime/src/datetime.rs index 479c59fa..e76b3b94 100644 --- a/crates/toml_datetime/src/datetime.rs +++ b/crates/toml_datetime/src/datetime.rs @@ -162,7 +162,7 @@ pub struct Time { pub minute: u8, /// Second: 0 to {58, 59, 60} (based on leap second rules) pub second: u8, - /// Nanosecond: 0 to 999_999_999 + /// Nanosecond: 0 to `999_999_999` pub nanosecond: u32, } @@ -179,7 +179,7 @@ pub enum Offset { /// Offset between local time and UTC Custom { - /// Minutes: -1_440..1_440 + /// Minutes: -`1_440..1_440` minutes: i16, }, } diff --git a/crates/toml_edit/src/de/mod.rs b/crates/toml_edit/src/de/mod.rs index 6638274b..391153f0 100644 --- a/crates/toml_edit/src/de/mod.rs +++ b/crates/toml_edit/src/de/mod.rs @@ -16,7 +16,6 @@ use array::ArrayDeserializer; use datetime::DatetimeDeserializer; use key::KeyDeserializer; use spanned::SpannedDeserializer; -use table::TableMapAccess; use table_enum::TableEnumDeserializer; pub use value::ValueDeserializer; diff --git a/crates/toml_edit/src/de/table.rs b/crates/toml_edit/src/de/table.rs index de8389c5..85adcc03 100644 --- a/crates/toml_edit/src/de/table.rs +++ b/crates/toml_edit/src/de/table.rs @@ -16,7 +16,7 @@ impl<'de> serde::Deserializer<'de> for TableDeserializer { where V: serde::de::Visitor<'de>, { - visitor.visit_map(crate::de::TableMapAccess::new(self)) + visitor.visit_map(TableMapAccess::new(self)) } // `None` is interpreted as a missing field so be sure to implement `Some` @@ -68,17 +68,17 @@ impl<'de> serde::Deserializer<'de> for TableDeserializer { V: serde::de::Visitor<'de>, { if self.items.is_empty() { - Err(crate::de::Error::custom( + Err(Error::custom( "wanted exactly 1 element, found 0 elements", self.span, )) } else if self.items.len() != 1 { - Err(crate::de::Error::custom( + Err(Error::custom( "wanted exactly 1 element, more than 1 element", self.span, )) } else { - visitor.visit_enum(crate::de::TableMapAccess::new(self)) + visitor.visit_enum(TableMapAccess::new(self)) } } diff --git a/crates/toml_edit/src/de/value.rs b/crates/toml_edit/src/de/value.rs index 28671f98..d7fb4a44 100644 --- a/crates/toml_edit/src/de/value.rs +++ b/crates/toml_edit/src/de/value.rs @@ -189,12 +189,12 @@ impl<'de> serde::Deserializer<'de> for ValueDeserializer { } crate::Item::Value(crate::Value::InlineTable(v)) => { if v.is_empty() { - Err(crate::de::Error::custom( + Err(Error::custom( "wanted exactly 1 element, found 0 elements", v.span(), )) } else if v.len() != 1 { - Err(crate::de::Error::custom( + Err(Error::custom( "wanted exactly 1 element, more than 1 element", v.span(), )) @@ -206,7 +206,7 @@ impl<'de> serde::Deserializer<'de> for ValueDeserializer { crate::Item::Table(v) => v .into_deserializer() .deserialize_enum(name, variants, visitor), - e => Err(crate::de::Error::custom("wanted string or table", e.span())), + e => Err(Error::custom("wanted string or table", e.span())), } .map_err(|mut e: Self::Error| { if e.span().is_none() { diff --git a/crates/toml_edit/src/item.rs b/crates/toml_edit/src/item.rs index b161e8ae..6e3aaafa 100644 --- a/crates/toml_edit/src/item.rs +++ b/crates/toml_edit/src/item.rs @@ -167,11 +167,11 @@ impl Item { // Starting private because the name is unclear pub(crate) fn make_item(&mut self) { let other = std::mem::take(self); - let other = match other.into_table().map(crate::Item::Table) { + let other = match other.into_table().map(Item::Table) { Ok(i) => i, Err(i) => i, }; - let other = match other.into_array_of_tables().map(crate::Item::ArrayOfTables) { + let other = match other.into_array_of_tables().map(Item::ArrayOfTables) { Ok(i) => i, Err(i) => i, }; diff --git a/crates/toml_edit/src/parser/value.rs b/crates/toml_edit/src/parser/value.rs index f050882a..776ab4f3 100644 --- a/crates/toml_edit/src/parser/value.rs +++ b/crates/toml_edit/src/parser/value.rs @@ -10,7 +10,6 @@ use crate::parser::numbers::{float, integer}; use crate::parser::prelude::*; use crate::parser::strings::string; use crate::repr::{Formatted, Repr}; -use crate::value as v; use crate::RawString; use crate::Value; @@ -20,56 +19,56 @@ pub(crate) fn value<'i>(check: RecursionCheck) -> impl Parser, Value, dispatch!{peek(any); crate::parser::strings::QUOTATION_MARK | crate::parser::strings::APOSTROPHE => string.map(|s| { - v::Value::String(Formatted::new( + Value::String(Formatted::new( s.into_owned() )) }), - crate::parser::array::ARRAY_OPEN => array(check).map(v::Value::Array), - crate::parser::inline_table::INLINE_TABLE_OPEN => inline_table(check).map(v::Value::InlineTable), + crate::parser::array::ARRAY_OPEN => array(check).map(Value::Array), + crate::parser::inline_table::INLINE_TABLE_OPEN => inline_table(check).map(Value::InlineTable), // Date/number starts b'+' | b'-' | b'0'..=b'9' => { // Uncommon enough not to be worth optimizing at this time alt(( date_time - .map(v::Value::from), + .map(Value::from), float - .map(v::Value::from), + .map(Value::from), integer - .map(v::Value::from), + .map(Value::from), )) }, // Report as if they were numbers because its most likely a typo b'_' => { integer - .map(v::Value::from) + .map(Value::from) .context(StrContext::Expected(StrContextValue::Description("leading digit"))) }, // Report as if they were numbers because its most likely a typo b'.' => { float - .map(v::Value::from) + .map(Value::from) .context(StrContext::Expected(StrContextValue::Description("leading digit"))) }, b't' => { - crate::parser::numbers::true_.map(v::Value::from) + crate::parser::numbers::true_.map(Value::from) .context(StrContext::Label("string")) .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, b'f' => { - crate::parser::numbers::false_.map(v::Value::from) + crate::parser::numbers::false_.map(Value::from) .context(StrContext::Label("string")) .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, b'i' => { - crate::parser::numbers::inf.map(v::Value::from) + crate::parser::numbers::inf.map(Value::from) .context(StrContext::Label("string")) .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) }, b'n' => { - crate::parser::numbers::nan.map(v::Value::from) + crate::parser::numbers::nan.map(Value::from) .context(StrContext::Label("string")) .context(StrContext::Expected(StrContextValue::CharLiteral('"'))) .context(StrContext::Expected(StrContextValue::CharLiteral('\''))) diff --git a/crates/toml_edit/src/ser/array.rs b/crates/toml_edit/src/ser/array.rs index 80eba8ba..a42cc661 100644 --- a/crates/toml_edit/src/ser/array.rs +++ b/crates/toml_edit/src/ser/array.rs @@ -21,9 +21,9 @@ impl serde::ser::SerializeSeq for SerializeValueArray { type Ok = crate::Value; type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let value = value.serialize(super::ValueSerializer {})?; self.values.push(crate::Item::Value(value)); @@ -39,9 +39,9 @@ impl serde::ser::SerializeTuple for SerializeValueArray { type Ok = crate::Value; type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<(), Error> + fn serialize_element(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { serde::ser::SerializeSeq::serialize_element(self, value) } @@ -55,9 +55,9 @@ impl serde::ser::SerializeTupleVariant for SerializeValueArray { type Ok = crate::Value; type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { serde::ser::SerializeSeq::serialize_element(self, value) } @@ -71,9 +71,9 @@ impl serde::ser::SerializeTupleStruct for SerializeValueArray { type Ok = crate::Value; type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { serde::ser::SerializeSeq::serialize_element(self, value) } diff --git a/crates/toml_edit/src/ser/key.rs b/crates/toml_edit/src/ser/key.rs index d5e381bf..3ba08406 100644 --- a/crates/toml_edit/src/ser/key.rs +++ b/crates/toml_edit/src/ser/key.rs @@ -75,9 +75,9 @@ impl serde::ser::Serializer for KeySerializer { Err(Error::KeyNotString) } - fn serialize_some(self, _value: &T) -> Result + fn serialize_some(self, _value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { Err(Error::KeyNotString) } @@ -99,18 +99,18 @@ impl serde::ser::Serializer for KeySerializer { Ok(variant.into()) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -118,7 +118,7 @@ impl serde::ser::Serializer for KeySerializer { _value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { Err(Error::KeyNotString) } diff --git a/crates/toml_edit/src/ser/map.rs b/crates/toml_edit/src/ser/map.rs index 1d1d8e05..49029028 100644 --- a/crates/toml_edit/src/ser/map.rs +++ b/crates/toml_edit/src/ser/map.rs @@ -24,9 +24,9 @@ impl serde::ser::SerializeMap for SerializeMap { type Ok = crate::Value; type Error = Error; - fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> + fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { match self { Self::Datetime(s) => s.serialize_key(input), @@ -34,9 +34,9 @@ impl serde::ser::SerializeMap for SerializeMap { } } - fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { match self { Self::Datetime(s) => s.serialize_value(value), @@ -56,13 +56,9 @@ impl serde::ser::SerializeStruct for SerializeMap { type Ok = crate::Value; type Error = 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: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { match self { Self::Datetime(s) => s.serialize_field(key, value), @@ -93,16 +89,16 @@ impl serde::ser::SerializeMap for SerializeDatetime { type Ok = crate::Datetime; type Error = Error; - fn serialize_key(&mut self, _input: &T) -> Result<(), Self::Error> + fn serialize_key(&mut self, _input: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { unreachable!("datetimes should only be serialized as structs, not maps") } - fn serialize_value(&mut self, _value: &T) -> Result<(), Self::Error> + fn serialize_value(&mut self, _value: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { unreachable!("datetimes should only be serialized as structs, not maps") } @@ -116,13 +112,9 @@ impl serde::ser::SerializeStruct for SerializeDatetime { type Ok = crate::Datetime; type Error = 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: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { if key == toml_datetime::__unstable::FIELD { self.value = Some(value.serialize(DatetimeFieldSerializer::default())?); @@ -161,17 +153,17 @@ impl serde::ser::SerializeMap for SerializeInlineTable { type Ok = crate::InlineTable; type Error = Error; - fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> + fn serialize_key(&mut self, input: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { self.key = Some(input.serialize(KeySerializer)?); Ok(()) } - fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> + fn serialize_value(&mut self, value: &T) -> Result<(), Self::Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let mut value_serializer = MapValueSerializer::new(); let res = value.serialize(&mut value_serializer); @@ -202,13 +194,9 @@ impl serde::ser::SerializeStruct for SerializeInlineTable { type Ok = crate::InlineTable; type Error = 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: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let mut value_serializer = MapValueSerializer::new(); let res = value.serialize(&mut value_serializer); @@ -308,9 +296,9 @@ impl serde::ser::Serializer for DatetimeFieldSerializer { Err(Error::DateInvalid) } - fn serialize_some(self, _value: &T) -> Result + fn serialize_some(self, _value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { Err(Error::DateInvalid) } @@ -332,18 +320,18 @@ impl serde::ser::Serializer for DatetimeFieldSerializer { Err(Error::DateInvalid) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, _value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { Err(Error::DateInvalid) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -351,7 +339,7 @@ impl serde::ser::Serializer for DatetimeFieldSerializer { _value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { Err(Error::DateInvalid) } @@ -488,9 +476,9 @@ impl serde::ser::Serializer for &mut MapValueSerializer { Err(Error::UnsupportedNone) } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { ValueSerializer::new().serialize_some(value) } @@ -512,18 +500,18 @@ impl serde::ser::Serializer for &mut MapValueSerializer { ValueSerializer::new().serialize_unit_variant(name, variant_index, variant) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, name: &'static str, value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { ValueSerializer::new().serialize_newtype_struct(name, value) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, name: &'static str, variant_index: u32, @@ -531,7 +519,7 @@ impl serde::ser::Serializer for &mut MapValueSerializer { value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { ValueSerializer::new().serialize_newtype_variant(name, variant_index, variant, value) } @@ -615,9 +603,9 @@ impl serde::ser::SerializeTupleVariant for SerializeVariant type Ok = crate::Value; type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<(), Error> + fn serialize_field(&mut self, value: &T) -> Result<(), Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { serde::ser::SerializeSeq::serialize_element(&mut self.inner, value) } diff --git a/crates/toml_edit/src/ser/mod.rs b/crates/toml_edit/src/ser/mod.rs index 7a3c4086..3cf00c30 100644 --- a/crates/toml_edit/src/ser/mod.rs +++ b/crates/toml_edit/src/ser/mod.rs @@ -85,9 +85,9 @@ impl std::error::Error for Error {} /// fail, if `T` contains a map with non-string keys, or if `T` attempts to /// serialize an unsupported datatype such as an enum, tuple, or tuple struct. #[cfg(feature = "display")] -pub fn to_vec(value: &T) -> Result, Error> +pub fn to_vec(value: &T) -> Result, Error> where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { to_string(value).map(|e| e.into_bytes()) } @@ -129,9 +129,9 @@ where /// println!("{}", toml) /// ``` #[cfg(feature = "display")] -pub fn to_string(value: &T) -> Result +pub fn to_string(value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { to_document(value).map(|e| e.to_string()) } @@ -141,9 +141,9 @@ where /// This is identical to `to_string` except the output string has a more /// "pretty" output. See `ValueSerializer::pretty` for more details. #[cfg(feature = "display")] -pub fn to_string_pretty(value: &T) -> Result +pub fn to_string_pretty(value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let mut document = to_document(value)?; pretty::Pretty.visit_document_mut(&mut document); @@ -153,9 +153,9 @@ where /// Serialize the given data structure into a TOML document. /// /// This would allow custom formatting to be applied, mixing with format preserving edits, etc. -pub fn to_document(value: &T) -> Result +pub fn to_document(value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let value = value.serialize(ValueSerializer::new())?; let item = crate::Item::Value(value); diff --git a/crates/toml_edit/src/ser/value.rs b/crates/toml_edit/src/ser/value.rs index 06c8ca6a..b67bd8af 100644 --- a/crates/toml_edit/src/ser/value.rs +++ b/crates/toml_edit/src/ser/value.rs @@ -144,9 +144,9 @@ impl serde::ser::Serializer for ValueSerializer { Err(Error::UnsupportedNone) } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { value.serialize(self) } @@ -168,18 +168,18 @@ impl serde::ser::Serializer for ValueSerializer { self.serialize_str(variant) } - fn serialize_newtype_struct( + fn serialize_newtype_struct( self, _name: &'static str, value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -187,7 +187,7 @@ impl serde::ser::Serializer for ValueSerializer { value: &T, ) -> Result where - T: serde::ser::Serialize, + T: serde::ser::Serialize + ?Sized, { let value = value.serialize(self)?; let mut table = crate::InlineTable::new(); diff --git a/crates/toml_edit/tests/testsuite/edit.rs b/crates/toml_edit/tests/testsuite/edit.rs index fcb5eb0e..a5df5ed2 100644 --- a/crates/toml_edit/tests/testsuite/edit.rs +++ b/crates/toml_edit/tests/testsuite/edit.rs @@ -1,4 +1,3 @@ -use std::fmt; use std::iter::FromIterator; use snapbox::assert_eq; @@ -19,19 +18,6 @@ macro_rules! as_table { }}; } -// Copied from https://github.com/colin-kiegel/rust-pretty-assertions/issues/24 -/// Wrapper around string slice that makes debug output `{:?}` to print string same way as `{}`. -/// Used in different `assert*!` macros in combination with `pretty_assertions` crate to make -/// test failures to show nice diffs. -#[derive(PartialEq, Eq)] -struct PrettyString<'a>(pub(crate) &'a str); -/// Make diff to display string as multi-line string -impl<'a> fmt::Debug for PrettyString<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(self.0) - } -} - struct Test { doc: DocumentMut, }