Skip to content

Commit

Permalink
minor: update bson to clippy 1.80.0 (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
abr-egn authored Jul 26, 2024
1 parent 2e8fb00 commit d0f5d23
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .evergreen/check-clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 4 additions & 7 deletions src/bson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/de/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/extjson/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl TryFrom<serde_json::Value> 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)
Expand Down
3 changes: 1 addition & 2 deletions src/extjson/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
//!
Expand Down
6 changes: 3 additions & 3 deletions src/extjson/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub(crate) struct Double {
impl Double {
pub(crate) fn parse(self) -> extjson::de::Result<f64> {
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(
Expand Down
2 changes: 1 addition & 1 deletion src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 8 additions & 11 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ fn write_binary<W: Write>(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<T: ?Sized>(value: &T) -> Result<Bson>
pub fn to_bson<T>(value: &T) -> Result<Bson>
where
T: Serialize,
T: Serialize + ?Sized,
{
let ser = Serializer::new();
value.serialize(ser)
Expand All @@ -136,9 +136,9 @@ where
/// assert_eq!(bson, bson!({ "a": "ok" }));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn to_bson_with_options<T: ?Sized>(value: &T, options: SerializerOptions) -> Result<Bson>
pub fn to_bson_with_options<T>(value: &T, options: SerializerOptions) -> Result<Bson>
where
T: Serialize,
T: Serialize + ?Sized,
{
let ser = Serializer::new_with_options(options);
value.serialize(ser)
Expand All @@ -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<T: ?Sized>(value: &T) -> Result<Document>
pub fn to_document<T>(value: &T) -> Result<Document>
where
T: Serialize,
T: Serialize + ?Sized,
{
to_document_with_options(value, Default::default())
}
Expand All @@ -175,12 +175,9 @@ where
/// assert_eq!(doc, doc! { "a": "ok" });
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn to_document_with_options<T: ?Sized>(
value: &T,
options: SerializerOptions,
) -> Result<Document>
pub fn to_document_with_options<T>(value: &T, options: SerializerOptions) -> Result<Document>
where
T: Serialize,
T: Serialize + ?Sized,
{
match to_bson_with_options(value, options)? {
Bson::Document(doc) => Ok(doc),
Expand Down
36 changes: 18 additions & 18 deletions src/ser/raw/document_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ impl<'a> serde::ser::SerializeSeq for DocumentSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_element<T>(&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| {
Expand All @@ -97,17 +97,17 @@ impl<'a> serde::ser::SerializeMap for DocumentSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<()>
fn serialize_key<T>(&mut self, key: &T) -> Result<()>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
self.serialize_doc_key(key)
}

#[inline]
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_value<T>(&mut self, value: &T) -> Result<()>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
value.serialize(&mut *self.root_serializer)
}
Expand All @@ -123,9 +123,9 @@ impl<'a> serde::ser::SerializeStruct for DocumentSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<()>
fn serialize_field<T>(&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)
Expand All @@ -143,9 +143,9 @@ impl<'a> serde::ser::SerializeTuple for DocumentSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_element<T>(&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)
Expand All @@ -163,9 +163,9 @@ impl<'a> serde::ser::SerializeTupleStruct for DocumentSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_field<T>(&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)
Expand Down Expand Up @@ -278,9 +278,9 @@ impl<'a> serde::Serializer for KeySerializer<'a> {
}

#[inline]
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok>
where
T: Serialize,
T: Serialize + ?Sized,
{
value.serialize(self)
}
Expand All @@ -306,23 +306,23 @@ impl<'a> serde::Serializer for KeySerializer<'a> {
}

#[inline]
fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> Result<Self::Ok>
fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> Result<Self::Ok>
where
T: Serialize,
T: Serialize + ?Sized,
{
value.serialize(self)
}

#[inline]
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
value: &T,
) -> Result<Self::Ok>
where
T: Serialize,
T: Serialize + ?Sized,
{
Err(Self::invalid_key(value))
}
Expand Down
24 changes: 12 additions & 12 deletions src/ser/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ impl<'a> serde::Serializer for &'a mut Serializer {
}

#[inline]
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
value.serialize(self)
}
Expand All @@ -264,9 +264,9 @@ impl<'a> serde::Serializer for &'a mut Serializer {
}

#[inline]
fn serialize_newtype_struct<T: ?Sized>(self, name: &'static str, value: &T) -> Result<Self::Ok>
fn serialize_newtype_struct<T>(self, name: &'static str, value: &T) -> Result<Self::Ok>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
match name {
UUID_NEWTYPE_NAME => self.hint = SerializerHint::Uuid,
Expand All @@ -285,15 +285,15 @@ impl<'a> serde::Serializer for &'a mut Serializer {
}

#[inline]
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_name: &'static str,
_variant_index: u32,
variant: &'static str,
value: &T,
) -> Result<Self::Ok>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
self.update_element_type(ElementType::EmbeddedDocument)?;
let mut d = DocumentSerializer::start(&mut *self)?;
Expand Down Expand Up @@ -396,9 +396,9 @@ impl<'a> SerializeStruct for StructSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<()>
fn serialize_field<T>(&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),
Expand Down Expand Up @@ -499,9 +499,9 @@ impl<'a> serde::ser::SerializeTupleVariant for VariantSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
T: Serialize,
T: Serialize + ?Sized,
{
self.serialize_element(format!("{}", self.num_elements_serialized).as_str(), value)
}
Expand All @@ -518,9 +518,9 @@ impl<'a> serde::ser::SerializeStructVariant for VariantSerializer<'a> {
type Error = Error;

#[inline]
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<()>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
where
T: Serialize,
T: Serialize + ?Sized,
{
self.serialize_element(key, value)
}
Expand Down
Loading

0 comments on commit d0f5d23

Please sign in to comment.