Skip to content

Commit 41f4475

Browse files
committed
fix: clippy warnings for mssql, any, postgres, and sqlite modules
- Remove empty line after doc comment in tls_prelogin_stream_wrapper.rs - Fix needless_borrow in ustr.rs, logger.rs, any/statement.rs - Fix unneeded_return in logger.rs - Add allow for large_enum_variant in AnyConnectionKind - Fix never_loop in postgres time_tz.rs by simplifying DateTime parsing - Fix module_inception by renaming time module to time_impl - Fix manual_div_ceil using div_ceil method - Fix deref which would be done by auto-deref in sqlite/column.rs - Fix wrong_self_convention by making as_int take &self - Fix useless_conversion and needless_borrow in sqlite/connection/execute.rs
1 parent 28311cd commit 41f4475

File tree

9 files changed

+12
-26
lines changed

9 files changed

+12
-26
lines changed

sqlx-core/src/any/connection/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct AnyConnection(pub(super) AnyConnectionKind);
3535
#[derive(Debug)]
3636
// Used internally in `sqlx-macros`
3737
#[doc(hidden)]
38+
#[allow(clippy::large_enum_variant)]
3839
pub enum AnyConnectionKind {
3940
#[cfg(feature = "postgres")]
4041
Postgres(postgres::PgConnection),

sqlx-core/src/any/statement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'q> Statement<'q> for AnyStatement<'q> {
3333

3434
fn parameters(&self) -> Option<Either<&[AnyTypeInfo], usize>> {
3535
match &self.parameters {
36-
Some(Either::Left(types)) => Some(Either::Left(&types)),
36+
Some(Either::Left(types)) => Some(Either::Left(types)),
3737
Some(Either::Right(count)) => Some(Either::Right(*count)),
3838
None => None,
3939
}
@@ -54,7 +54,7 @@ where
5454
statement
5555
.column_names
5656
.get(*self)
57+
.copied()
5758
.ok_or_else(|| Error::ColumnNotFound((*self).into()))
58-
.map(|v| *v)
5959
}
6060
}

sqlx-core/src/postgres/types/bit_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Decode<'_, Postgres> for BitVec {
6565
};
6666

6767
// The smallest amount of data we can read is one byte
68-
let bytes_len = (len + 7) / 8;
68+
let bytes_len = len.div_ceil(8);
6969

7070
if bytes.remaining() != bytes_len {
7171
Err(io::Error::new(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod date;
22
mod datetime;
3-
mod time;
3+
mod time_impl;
44

55
#[rustfmt::skip]
66
const PG_EPOCH: ::time::Date = ::time::macros::date!(2000-1-1);
File renamed without changes.

sqlx-core/src/postgres/types/time_tz.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,8 @@ mod chrono {
9999
tmp.push_str("2001-07-08 ");
100100
tmp.push_str(s);
101101

102-
let dt = 'out: loop {
103-
let mut err = None;
104-
105-
for fmt in &["%Y-%m-%d %H:%M:%S%.f%#z", "%Y-%m-%d %H:%M:%S%.f"] {
106-
match DateTime::parse_from_str(&tmp, fmt) {
107-
Ok(dt) => {
108-
break 'out dt;
109-
}
110-
111-
Err(error) => {
112-
err = Some(error);
113-
}
114-
}
115-
}
116-
117-
return Err(err.unwrap().into());
118-
};
102+
let dt = DateTime::parse_from_str(&tmp, "%Y-%m-%d %H:%M:%S%.f%#z")
103+
.or_else(|_| DateTime::parse_from_str(&tmp, "%Y-%m-%d %H:%M:%S%.f"))?;
119104

120105
let time = dt.time();
121106
let offset = *dt.offset();

sqlx-core/src/sqlite/column.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Column for SqliteColumn {
2020
}
2121

2222
fn name(&self) -> &str {
23-
&*self.name
23+
&self.name
2424
}
2525

2626
fn type_info(&self) -> &SqliteTypeInfo {

sqlx-core/src/sqlite/connection/establish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum SqliteLoadExtensionMode {
2828
}
2929

3030
impl SqliteLoadExtensionMode {
31-
fn as_int(self) -> c_int {
31+
fn as_int(&self) -> c_int {
3232
match self {
3333
SqliteLoadExtensionMode::Enable => 1,
3434
SqliteLoadExtensionMode::DisableAll => 0,

sqlx-core/src/sqlite/connection/execute.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Iterator for ExecuteIter<'_> {
7171
let mut statement = match self.statement.prepare_next(self.handle) {
7272
Ok(Some(statement)) => statement,
7373
Ok(None) => return None,
74-
Err(e) => return Some(Err(e.into())),
74+
Err(e) => return Some(Err(e)),
7575
};
7676

7777
self.goto_next = false;
@@ -83,7 +83,7 @@ impl Iterator for ExecuteIter<'_> {
8383

8484
statement.handle.clear_bindings();
8585

86-
match bind(&mut statement.handle, &self.args, self.args_used) {
86+
match bind(&mut statement.handle, self.args, self.args_used) {
8787
Ok(args_used) => self.args_used += args_used,
8888
Err(e) => return Some(Err(e)),
8989
}
@@ -100,7 +100,7 @@ impl Iterator for ExecuteIter<'_> {
100100
Some(Ok(Either::Right(SqliteRow::current(
101101
&statement.handle,
102102
&statement.columns,
103-
&statement.column_names,
103+
statement.column_names,
104104
))))
105105
}
106106
Ok(false) => {

0 commit comments

Comments
 (0)