Skip to content

Commit ad510f2

Browse files
committed
fix: clippy warnings in mysql types and migrate modules
- Fix let_and_return in mysql/types/float.rs - Fix needless_borrows_for_generic_args in chrono and time modules - Fix len_zero by using is_empty() - Fix unnecessary_cast by removing redundant type casts - Fix unwrap_or_default usage - Fix needless_borrow in json module - Fix needless_option_as_deref in value module - Fix get_first by using first() instead of get(0) - Fix needless_return in migrate module
1 parent 42bba3a commit ad510f2

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

sqlx-core/src/mysql/migrate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
192192
.map_err(MigrateError::AccessMigrationMetadata)?;
193193

194194
if let Some(checksum) = checksum {
195-
return if checksum == &*migration.checksum {
195+
if checksum == &*migration.checksum {
196196
Ok(())
197197
} else {
198198
Err(MigrateError::VersionMismatch(migration.version))
199-
};
199+
}
200200
} else {
201201
Err(MigrateError::VersionMissing(migration.version))
202202
}

sqlx-core/src/mysql/types/chrono.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<T: TimeZone> Type<MySql> for DateTime<T> {
2525
/// Note: assumes the connection's `time_zone` is set to `+00:00` (UTC).
2626
impl Encode<'_, MySql> for DateTime<Utc> {
2727
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
28-
Encode::<MySql>::encode(&self.naive_utc(), buf)
28+
Encode::<MySql>::encode(self.naive_utc(), buf)
2929
}
3030
}
3131

@@ -40,7 +40,7 @@ impl<'r> Decode<'r, MySql> for DateTime<Utc> {
4040
/// Note: assumes the connection's `time_zone` is set to `+00:00` (UTC).
4141
impl Encode<'_, MySql> for DateTime<Local> {
4242
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
43-
Encode::<MySql>::encode(&self.naive_utc(), buf)
43+
Encode::<MySql>::encode(self.naive_utc(), buf)
4444
}
4545
}
4646

@@ -242,7 +242,7 @@ fn encode_date(date: &NaiveDate, buf: &mut Vec<u8>) {
242242
}
243243

244244
fn decode_date(mut buf: &[u8]) -> Option<NaiveDate> {
245-
if buf.len() == 0 {
245+
if buf.is_empty() {
246246
// MySQL specifies that if there are no bytes, this is all zeros
247247
None
248248
} else {
@@ -257,7 +257,7 @@ fn encode_time(time: &NaiveTime, include_micros: bool, buf: &mut Vec<u8>) {
257257
buf.push(time.second() as u8);
258258

259259
if include_micros {
260-
buf.extend(&((time.nanosecond() / 1000) as u32).to_le_bytes());
260+
buf.extend(&(time.nanosecond() / 1000).to_le_bytes());
261261
}
262262
}
263263

@@ -274,5 +274,5 @@ fn decode_time(len: u8, mut buf: &[u8]) -> NaiveTime {
274274
};
275275

276276
NaiveTime::from_hms_micro_opt(hour as u32, minute as u32, seconds as u32, micros as u32)
277-
.unwrap_or_else(NaiveTime::default)
277+
.unwrap_or_default()
278278
}

sqlx-core/src/mysql/types/float.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ impl Decode<'_, MySql> for f64 {
7373
}
7474
_ => {
7575
let str_val = value.as_str()?;
76-
let parsed = str_val.parse()?;
77-
parsed
76+
str_val.parse()?
7877
}
7978
})
8079
}

sqlx-core/src/mysql/types/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError> {
4242
let string_value = <&str as Decode<MySql>>::decode(value)?;
4343

44-
serde_json::from_str(&string_value)
44+
serde_json::from_str(string_value)
4545
.map(Json)
4646
.map_err(Into::into)
4747
}

sqlx-core/src/mysql/types/time.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Encode<'_, MySql> for OffsetDateTime {
2626
let utc_dt = self.to_offset(UtcOffset::UTC);
2727
let primitive_dt = PrimitiveDateTime::new(utc_dt.date(), utc_dt.time());
2828

29-
Encode::<MySql>::encode(&primitive_dt, buf)
29+
Encode::<MySql>::encode(primitive_dt, buf)
3030
}
3131
}
3232

@@ -238,8 +238,8 @@ fn decode_date(buf: &[u8]) -> Result<Option<Date>, BoxDynError> {
238238

239239
Date::from_calendar_date(
240240
LittleEndian::read_u16(buf) as i32,
241-
time::Month::try_from(buf[2] as u8)?,
242-
buf[3] as u8,
241+
time::Month::try_from(buf[2])?,
242+
buf[3],
243243
)
244244
.map_err(Into::into)
245245
.map(Some)
@@ -251,7 +251,7 @@ fn encode_time(time: &Time, include_micros: bool, buf: &mut Vec<u8>) {
251251
buf.push(time.second());
252252

253253
if include_micros {
254-
buf.extend(&((time.nanosecond() / 1000) as u32).to_le_bytes());
254+
buf.extend(&(time.nanosecond() / 1000).to_le_bytes());
255255
}
256256
}
257257

sqlx-core/src/mysql/value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'r> ValueRef<'r> for MySqlValueRef<'r> {
9393

9494
#[inline]
9595
fn is_null(&self) -> bool {
96-
is_null(self.value.as_deref(), &self.type_info)
96+
is_null(self.value, &self.type_info)
9797
}
9898
}
9999

@@ -125,7 +125,7 @@ fn is_null(value: Option<&[u8]>, ty: &MySqlTypeInfo) -> bool {
125125
if matches!(
126126
ty.r#type,
127127
ColumnType::Date | ColumnType::Timestamp | ColumnType::Datetime
128-
) && (value.get(0) == Some(&0)
128+
) && (value.first() == Some(&0)
129129
|| value == b"0000-00-00"
130130
|| value == b"0000-00-00 00:00:00")
131131
{

0 commit comments

Comments
 (0)