From 748976003e153969fd8a209f77ba7f2d907eebdd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 30 Apr 2022 20:11:04 -0700 Subject: [PATCH] Resolve type_repetition_in_bounds clippy lint error: this type has already been used as a bound predicate --> src/ser.rs:189:9 | 189 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::type-repetition-in-bounds` implied by `-D clippy::pedantic` = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:203:9 | 203 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:217:9 | 217 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:298:9 | 298 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:318:9 | 318 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:338:9 | 338 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:358:9 | 358 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:378:9 | 378 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:385:9 | 385 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:392:9 | 392 | K: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `K: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:393:9 | 393 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:413:9 | 413 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:433:9 | 433 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:566:9 | 566 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:579:9 | 579 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:590:9 | 590 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:685:9 | 685 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:702:9 | 702 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:718:9 | 718 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:734:9 | 734 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:751:9 | 751 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:759:9 | 759 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:770:9 | 770 | K: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `K: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:771:9 | 771 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:788:9 | 788 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:805:9 | 805 | V: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `V: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:823:5 | 823 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:834:5 | 834 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/ser.rs:847:5 | 847 | T: ser::Serialize, | ^^^^^^^^^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + ser::Serialize` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/value/index.rs:126:5 | 126 | T: Index, | ^^^^^^^^ | = help: consider combining the bounds: `T: Sized + Index` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds error: this type has already been used as a bound predicate --> src/value/index.rs:146:48 | 146 | impl<'a, T: ?Sized> Sealed for &'a T where T: Sealed {} | ^^^^^^^^^ | = help: consider combining the bounds: `T: Sized + Sealed` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds --- src/ser.rs | 112 ++++++++++++++++++++++----------------------- src/value/index.rs | 6 +-- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/ser.rs b/src/ser.rs index b584f35a..f393172a 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -184,15 +184,15 @@ where self.write(doc) } - fn serialize_newtype_struct(self, name: &'static str, value: &T) -> Result<()> + fn serialize_newtype_struct(self, name: &'static str, value: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { let doc = SerializerToYaml.serialize_newtype_struct(name, value)?; self.write(doc) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, name: &'static str, variant_index: u32, @@ -200,7 +200,7 @@ where value: &T, ) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { let doc = SerializerToYaml.serialize_newtype_variant(name, variant_index, variant, value)?; @@ -212,9 +212,9 @@ where self.write(doc) } - fn serialize_some(self, value: &V) -> Result<()> + fn serialize_some(self, value: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { let doc = SerializerToYaml.serialize_some(value)?; self.write(doc) @@ -293,9 +293,9 @@ where type Ok = (); type Error = Error; - fn serialize_element(&mut self, elem: &T) -> Result<()> + fn serialize_element(&mut self, elem: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { self.delegate.serialize_element(elem) } @@ -313,9 +313,9 @@ where type Ok = (); type Error = Error; - fn serialize_element(&mut self, elem: &T) -> Result<()> + fn serialize_element(&mut self, elem: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { self.delegate.serialize_element(elem) } @@ -333,9 +333,9 @@ where type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &V) -> Result<()> + fn serialize_field(&mut self, value: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { self.delegate.serialize_field(value) } @@ -353,9 +353,9 @@ where type Ok = (); type Error = Error; - fn serialize_field(&mut self, v: &V) -> Result<()> + fn serialize_field(&mut self, v: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { self.delegate.serialize_field(v) } @@ -373,24 +373,24 @@ where type Ok = (); type Error = Error; - fn serialize_key(&mut self, key: &T) -> Result<()> + fn serialize_key(&mut self, key: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { self.delegate.serialize_key(key) } - fn serialize_value(&mut self, value: &T) -> Result<()> + fn serialize_value(&mut self, value: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { self.delegate.serialize_value(value) } - fn serialize_entry(&mut self, key: &K, value: &V) -> Result<()> + fn serialize_entry(&mut self, key: &K, value: &V) -> Result<()> where - K: ser::Serialize, - V: ser::Serialize, + K: ?Sized + ser::Serialize, + V: ?Sized + ser::Serialize, { self.delegate.serialize_entry(key, value) } @@ -408,9 +408,9 @@ where type Ok = (); type Error = Error; - fn serialize_field(&mut self, key: &'static str, value: &V) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { self.delegate.serialize_field(key, value) } @@ -428,9 +428,9 @@ where type Ok = (); type Error = Error; - fn serialize_field(&mut self, field: &'static str, v: &V) -> Result<()> + fn serialize_field(&mut self, field: &'static str, v: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { self.delegate.serialize_field(field, v) } @@ -561,14 +561,14 @@ impl ser::Serializer for SerializerToYaml { Ok(Yaml::String(variant.to_owned())) } - fn serialize_newtype_struct(self, _name: &'static str, value: &T) -> Result + fn serialize_newtype_struct(self, _name: &'static str, value: &T) -> Result where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &str, _variant_index: u32, @@ -576,7 +576,7 @@ impl ser::Serializer for SerializerToYaml { value: &T, ) -> Result where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { Ok(singleton_hash(to_yaml(variant)?, to_yaml(value)?)) } @@ -585,9 +585,9 @@ impl ser::Serializer for SerializerToYaml { self.serialize_unit() } - fn serialize_some(self, value: &V) -> Result + fn serialize_some(self, value: &V) -> Result where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { value.serialize(self) } @@ -680,9 +680,9 @@ impl ser::SerializeSeq for SerializeArray { type Ok = yaml::Yaml; type Error = Error; - fn serialize_element(&mut self, elem: &T) -> Result<()> + fn serialize_element(&mut self, elem: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { self.array.push(to_yaml(elem)?); Ok(()) @@ -697,9 +697,9 @@ impl ser::SerializeTuple for SerializeArray { type Ok = yaml::Yaml; type Error = Error; - fn serialize_element(&mut self, elem: &T) -> Result<()> + fn serialize_element(&mut self, elem: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { ser::SerializeSeq::serialize_element(self, elem) } @@ -713,9 +713,9 @@ impl ser::SerializeTupleStruct for SerializeArray { type Ok = yaml::Yaml; type Error = Error; - fn serialize_field(&mut self, value: &V) -> Result<()> + fn serialize_field(&mut self, value: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { ser::SerializeSeq::serialize_element(self, value) } @@ -729,9 +729,9 @@ impl ser::SerializeTupleVariant for SerializeTupleVariant { type Ok = yaml::Yaml; type Error = Error; - fn serialize_field(&mut self, v: &V) -> Result<()> + fn serialize_field(&mut self, v: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { self.array.push(to_yaml(v)?); Ok(()) @@ -746,17 +746,17 @@ impl ser::SerializeMap for SerializeMap { type Ok = yaml::Yaml; type Error = Error; - fn serialize_key(&mut self, key: &T) -> Result<()> + fn serialize_key(&mut self, key: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { self.next_key = Some(to_yaml(key)?); Ok(()) } - fn serialize_value(&mut self, value: &T) -> Result<()> + fn serialize_value(&mut self, value: &T) -> Result<()> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { match self.next_key.take() { Some(key) => self.hash.insert(key, to_yaml(value)?), @@ -765,10 +765,10 @@ impl ser::SerializeMap for SerializeMap { Ok(()) } - fn serialize_entry(&mut self, key: &K, value: &V) -> Result<()> + fn serialize_entry(&mut self, key: &K, value: &V) -> Result<()> where - K: ser::Serialize, - V: ser::Serialize, + K: ?Sized + ser::Serialize, + V: ?Sized + ser::Serialize, { self.hash.insert(to_yaml(key)?, to_yaml(value)?); Ok(()) @@ -783,9 +783,9 @@ impl ser::SerializeStruct for SerializeStruct { type Ok = yaml::Yaml; type Error = Error; - fn serialize_field(&mut self, key: &'static str, value: &V) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { self.hash.insert(to_yaml(key)?, to_yaml(value)?); Ok(()) @@ -800,9 +800,9 @@ impl ser::SerializeStructVariant for SerializeStructVariant { type Ok = yaml::Yaml; type Error = Error; - fn serialize_field(&mut self, field: &'static str, v: &V) -> Result<()> + fn serialize_field(&mut self, field: &'static str, v: &V) -> Result<()> where - V: ser::Serialize, + V: ?Sized + ser::Serialize, { self.hash.insert(to_yaml(field)?, to_yaml(v)?); Ok(()) @@ -817,10 +817,10 @@ impl ser::SerializeStructVariant for SerializeStructVariant { /// /// Serialization can fail if `T`'s implementation of `Serialize` decides to /// return an error. -pub fn to_writer(writer: W, value: &T) -> Result<()> +pub fn to_writer(writer: W, value: &T) -> Result<()> where W: io::Write, - T: ser::Serialize, + T: ?Sized + ser::Serialize, { value.serialize(&mut Serializer::new(writer)) } @@ -829,9 +829,9 @@ where /// /// Serialization can fail if `T`'s implementation of `Serialize` decides to /// return an error. -pub fn to_vec(value: &T) -> Result> +pub fn to_vec(value: &T) -> Result> where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { let mut vec = Vec::with_capacity(128); to_writer(&mut vec, value)?; @@ -842,9 +842,9 @@ where /// /// Serialization can fail if `T`'s implementation of `Serialize` decides to /// return an error. -pub fn to_string(value: &T) -> Result +pub fn to_string(value: &T) -> Result where - T: ser::Serialize, + T: ?Sized + ser::Serialize, { String::from_utf8(to_vec(value)?).map_err(error::string_utf8) } diff --git a/src/value/index.rs b/src/value/index.rs index 4f38e0cb..b5f5e901 100644 --- a/src/value/index.rs +++ b/src/value/index.rs @@ -121,9 +121,9 @@ impl Index for String { } } -impl<'a, T: ?Sized> Index for &'a T +impl<'a, T> Index for &'a T where - T: Index, + T: ?Sized + Index, { fn index_into<'v>(&self, v: &'v Value) -> Option<&'v Value> { (**self).index_into(v) @@ -143,7 +143,7 @@ mod private { impl Sealed for str {} impl Sealed for String {} impl Sealed for super::Value {} - impl<'a, T: ?Sized> Sealed for &'a T where T: Sealed {} + impl<'a, T> Sealed for &'a T where T: ?Sized + Sealed {} } /// Used in panic messages.