diff --git a/.evergreen/check-clippy.sh b/.evergreen/check-clippy.sh index 9a809142..c41008d5 100755 --- a/.evergreen/check-clippy.sh +++ b/.evergreen/check-clippy.sh @@ -5,7 +5,7 @@ set -o errexit . ~/.cargo/env # Pin clippy to the latest version. This should be updated when new versions of Rust are released. -CLIPPY_VERSION=1.75.0 +CLIPPY_VERSION=1.80.0 rustup install $CLIPPY_VERSION diff --git a/src/bson.rs b/src/bson.rs index 6c8c905e..5ecb06dd 100644 --- a/src/bson.rs +++ b/src/bson.rs @@ -695,9 +695,9 @@ impl Bson { } ["$numberDouble"] => match doc.get_str("$numberDouble") { - Ok("Infinity") => return Bson::Double(std::f64::INFINITY), - Ok("-Infinity") => return Bson::Double(std::f64::NEG_INFINITY), - Ok("NaN") => return Bson::Double(std::f64::NAN), + Ok("Infinity") => return Bson::Double(f64::INFINITY), + Ok("-Infinity") => return Bson::Double(f64::NEG_INFINITY), + Ok("NaN") => return Bson::Double(f64::NAN), Ok(other) => { if let Ok(d) = other.parse() { return Bson::Double(d); @@ -758,10 +758,7 @@ impl Bson { if let Ok(t) = timestamp.get_i64("t") { if let Ok(i) = timestamp.get_i64("i") { - if t >= 0 - && i >= 0 - && t <= (std::u32::MAX as i64) - && i <= (std::u32::MAX as i64) + if t >= 0 && i >= 0 && t <= (u32::MAX as i64) && i <= (u32::MAX as i64) { return Bson::Timestamp(Timestamp { time: t as u32, diff --git a/src/de/serde.rs b/src/de/serde.rs index 4b73859d..ecf35935 100644 --- a/src/de/serde.rs +++ b/src/de/serde.rs @@ -359,9 +359,9 @@ impl<'de> Visitor<'de> for BsonVisitor { "$numberDouble" => { let string: String = visitor.next_value()?; let val = match string.as_str() { - "Infinity" => Bson::Double(std::f64::INFINITY), - "-Infinity" => Bson::Double(std::f64::NEG_INFINITY), - "NaN" => Bson::Double(std::f64::NAN), + "Infinity" => Bson::Double(f64::INFINITY), + "-Infinity" => Bson::Double(f64::NEG_INFINITY), + "NaN" => Bson::Double(f64::NAN), _ => Bson::Double(string.parse().map_err(|_| { V::Error::invalid_value( Unexpected::Str(&string), diff --git a/src/extjson/de.rs b/src/extjson/de.rs index e4683391..82b8fcde 100644 --- a/src/extjson/de.rs +++ b/src/extjson/de.rs @@ -182,7 +182,7 @@ impl TryFrom for Bson { serde_json::Value::Number(x) => x .as_i64() .map(|i| { - if i >= std::i32::MIN as i64 && i <= std::i32::MAX as i64 { + if i >= i32::MIN as i64 && i <= i32::MAX as i64 { Bson::Int32(i as i32) } else { Bson::Int64(i) diff --git a/src/extjson/mod.rs b/src/extjson/mod.rs index 32e94455..a23ca419 100644 --- a/src/extjson/mod.rs +++ b/src/extjson/mod.rs @@ -26,8 +26,7 @@ //! There are two modes of extJSON: "Canonical" and "Relaxed". They are the same except for the //! following differences: //! - In relaxed mode, all BSON numbers are represented by the JSON number type, rather than the -//! object -//! notation. +//! object notation. //! - In relaxed mode, the string in the datetime object notation is RFC 3339 (ISO-8601) formatted //! (if the date is after 1970). //! diff --git a/src/extjson/models.rs b/src/extjson/models.rs index 8e738c35..b91d5f67 100644 --- a/src/extjson/models.rs +++ b/src/extjson/models.rs @@ -57,9 +57,9 @@ pub(crate) struct Double { impl Double { pub(crate) fn parse(self) -> extjson::de::Result { match self.value.as_str() { - "Infinity" => Ok(std::f64::INFINITY), - "-Infinity" => Ok(std::f64::NEG_INFINITY), - "NaN" => Ok(std::f64::NAN), + "Infinity" => Ok(f64::INFINITY), + "-Infinity" => Ok(f64::NEG_INFINITY), + "NaN" => Ok(f64::NAN), other => { let d: f64 = other.parse().map_err(|_| { extjson::de::Error::invalid_value( diff --git a/src/oid.rs b/src/oid.rs index 89374a7e..9cec640e 100644 --- a/src/oid.rs +++ b/src/oid.rs @@ -332,7 +332,7 @@ fn test_counter_overflow_u24_max() { #[test] fn test_counter_overflow_usize_max() { let _guard = LOCK.run_exclusively(); - let start = usize::max_value(); + let start = usize::MAX; OID_COUNTER.store(start, Ordering::SeqCst); // Test counter overflows to u24_max when set to usize_max let oid = ObjectId::new(); diff --git a/src/ser/mod.rs b/src/ser/mod.rs index b35e51cd..d2faf636 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -112,9 +112,9 @@ fn write_binary(mut writer: W, bytes: &[u8], subtype: BinarySubtype) - /// the format is human readable or not. To serialize to a [`Document`] with a serializer that /// presents itself as not human readable, use [`to_bson_with_options`] with /// [`SerializerOptions::human_readable`] set to false. -pub fn to_bson(value: &T) -> Result +pub fn to_bson(value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { let ser = Serializer::new(); value.serialize(ser) @@ -136,9 +136,9 @@ where /// assert_eq!(bson, bson!({ "a": "ok" })); /// # Ok::<(), Box>(()) /// ``` -pub fn to_bson_with_options(value: &T, options: SerializerOptions) -> Result +pub fn to_bson_with_options(value: &T, options: SerializerOptions) -> Result where - T: Serialize, + T: Serialize + ?Sized, { let ser = Serializer::new_with_options(options); value.serialize(ser) @@ -152,9 +152,9 @@ where /// the format is human readable or not. To serialize to a [`Document`] with a serializer that /// presents itself as not human readable, use [`to_document_with_options`] with /// [`SerializerOptions::human_readable`] set to false. -pub fn to_document(value: &T) -> Result +pub fn to_document(value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { to_document_with_options(value, Default::default()) } @@ -175,12 +175,9 @@ where /// assert_eq!(doc, doc! { "a": "ok" }); /// # Ok::<(), Box>(()) /// ``` -pub fn to_document_with_options( - value: &T, - options: SerializerOptions, -) -> Result +pub fn to_document_with_options(value: &T, options: SerializerOptions) -> Result where - T: Serialize, + T: Serialize + ?Sized, { match to_bson_with_options(value, options)? { Bson::Document(doc) => Ok(doc), diff --git a/src/ser/raw/document_serializer.rs b/src/ser/raw/document_serializer.rs index e3eb53ee..9b20f5b8 100644 --- a/src/ser/raw/document_serializer.rs +++ b/src/ser/raw/document_serializer.rs @@ -71,9 +71,9 @@ impl<'a> serde::ser::SerializeSeq for DocumentSerializer<'a> { type Error = Error; #[inline] - fn serialize_element(&mut self, value: &T) -> Result<()> + fn serialize_element(&mut self, value: &T) -> Result<()> where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { let index = self.num_keys_serialized; self.serialize_doc_key_custom(|rs| { @@ -97,17 +97,17 @@ impl<'a> serde::ser::SerializeMap for DocumentSerializer<'a> { type Error = Error; #[inline] - fn serialize_key(&mut self, key: &T) -> Result<()> + fn serialize_key(&mut self, key: &T) -> Result<()> where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { self.serialize_doc_key(key) } #[inline] - fn serialize_value(&mut self, value: &T) -> Result<()> + fn serialize_value(&mut self, value: &T) -> Result<()> where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { value.serialize(&mut *self.root_serializer) } @@ -123,9 +123,9 @@ impl<'a> serde::ser::SerializeStruct for DocumentSerializer<'a> { type Error = Error; #[inline] - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { self.serialize_doc_key(key)?; value.serialize(&mut *self.root_serializer) @@ -143,9 +143,9 @@ impl<'a> serde::ser::SerializeTuple for DocumentSerializer<'a> { type Error = Error; #[inline] - fn serialize_element(&mut self, value: &T) -> Result<()> + fn serialize_element(&mut self, value: &T) -> Result<()> where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { self.serialize_doc_key(&self.num_keys_serialized.to_string())?; value.serialize(&mut *self.root_serializer) @@ -163,9 +163,9 @@ impl<'a> serde::ser::SerializeTupleStruct for DocumentSerializer<'a> { type Error = Error; #[inline] - fn serialize_field(&mut self, value: &T) -> Result<()> + fn serialize_field(&mut self, value: &T) -> Result<()> where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { self.serialize_doc_key(&self.num_keys_serialized.to_string())?; value.serialize(&mut *self.root_serializer) @@ -278,9 +278,9 @@ impl<'a> serde::Serializer for KeySerializer<'a> { } #[inline] - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { value.serialize(self) } @@ -306,15 +306,15 @@ impl<'a> serde::Serializer for KeySerializer<'a> { } #[inline] - 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, { value.serialize(self) } #[inline] - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -322,7 +322,7 @@ impl<'a> serde::Serializer for KeySerializer<'a> { value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(Self::invalid_key(value)) } diff --git a/src/ser/raw/mod.rs b/src/ser/raw/mod.rs index 103627d2..1fb904f5 100644 --- a/src/ser/raw/mod.rs +++ b/src/ser/raw/mod.rs @@ -236,9 +236,9 @@ impl<'a> serde::Serializer for &'a mut Serializer { } #[inline] - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { value.serialize(self) } @@ -264,9 +264,9 @@ impl<'a> serde::Serializer for &'a mut Serializer { } #[inline] - fn serialize_newtype_struct(self, name: &'static str, value: &T) -> Result + fn serialize_newtype_struct(self, name: &'static str, value: &T) -> Result where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { match name { UUID_NEWTYPE_NAME => self.hint = SerializerHint::Uuid, @@ -285,7 +285,7 @@ impl<'a> serde::Serializer for &'a mut Serializer { } #[inline] - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -293,7 +293,7 @@ impl<'a> serde::Serializer for &'a mut Serializer { value: &T, ) -> Result where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { self.update_element_type(ElementType::EmbeddedDocument)?; let mut d = DocumentSerializer::start(&mut *self)?; @@ -396,9 +396,9 @@ impl<'a> SerializeStruct for StructSerializer<'a> { type Error = Error; #[inline] - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { match self { StructSerializer::Value(ref mut v) => (&mut *v).serialize_field(key, value), @@ -499,9 +499,9 @@ impl<'a> serde::ser::SerializeTupleVariant for VariantSerializer<'a> { type Error = Error; #[inline] - fn serialize_field(&mut self, value: &T) -> Result<()> + fn serialize_field(&mut self, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.serialize_element(format!("{}", self.num_elements_serialized).as_str(), value) } @@ -518,9 +518,9 @@ impl<'a> serde::ser::SerializeStructVariant for VariantSerializer<'a> { type Error = Error; #[inline] - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.serialize_element(key, value) } diff --git a/src/ser/raw/value_serializer.rs b/src/ser/raw/value_serializer.rs index 76d1a1c0..46fb8623 100644 --- a/src/ser/raw/value_serializer.rs +++ b/src/ser/raw/value_serializer.rs @@ -328,9 +328,9 @@ impl<'a, 'b> serde::Serializer for &'b mut ValueSerializer<'a> { } #[inline] - fn serialize_some(self, _value: &T) -> Result + fn serialize_some(self, _value: &T) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(self.invalid_step("some")) } @@ -356,9 +356,9 @@ impl<'a, 'b> serde::Serializer for &'b mut ValueSerializer<'a> { } #[inline] - 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, { match (&mut self.state, name) { ( @@ -376,7 +376,7 @@ impl<'a, 'b> serde::Serializer for &'b mut ValueSerializer<'a> { } #[inline] - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -384,7 +384,7 @@ impl<'a, 'b> serde::Serializer for &'b mut ValueSerializer<'a> { _value: &T, ) -> Result where - T: Serialize, + T: Serialize + ?Sized, { Err(self.invalid_step("newtype_variant")) } @@ -454,9 +454,9 @@ impl<'a, 'b> SerializeStruct for &'b mut ValueSerializer<'a> { type Ok = (); type Error = Error; - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { match (&self.state, key) { (SerializationStep::DateTime, "$date") => { @@ -602,17 +602,17 @@ impl<'a> SerializeMap for CodeWithScopeSerializer<'a> { type Error = Error; #[inline] - fn serialize_key(&mut self, key: &T) -> Result<()> + fn serialize_key(&mut self, key: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.doc.serialize_key(key) } #[inline] - fn serialize_value(&mut self, value: &T) -> Result<()> + fn serialize_value(&mut self, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.doc.serialize_value(value) } diff --git a/src/ser/serde.rs b/src/ser/serde.rs index b3a2389c..9b5ce313 100644 --- a/src/ser/serde.rs +++ b/src/ser/serde.rs @@ -266,9 +266,9 @@ impl ser::Serializer for Serializer { } #[inline] - fn serialize_some(self, value: &V) -> crate::ser::Result + fn serialize_some(self, value: &V) -> crate::ser::Result where - V: Serialize, + V: Serialize + ?Sized, { value.serialize(self) } @@ -294,13 +294,13 @@ impl ser::Serializer for Serializer { } #[inline] - fn serialize_newtype_struct( + fn serialize_newtype_struct( mut self, name: &'static str, value: &T, ) -> crate::ser::Result where - T: Serialize, + T: Serialize + ?Sized, { match name { UUID_NEWTYPE_NAME => { @@ -357,7 +357,7 @@ impl ser::Serializer for Serializer { } #[inline] - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -365,7 +365,7 @@ impl ser::Serializer for Serializer { value: &T, ) -> crate::ser::Result where - T: Serialize, + T: Serialize + ?Sized, { let mut newtype_variant = Document::new(); newtype_variant.insert(variant, to_bson_with_options(value, self.options)?); diff --git a/src/tests/modules/ser.rs b/src/tests/modules/ser.rs index 3b93bbb7..48aa6596 100644 --- a/src/tests/modules/ser.rs +++ b/src/tests/modules/ser.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, u16, u32, u64, u8}; +use std::collections::BTreeMap; use assert_matches::assert_matches;