Skip to content

Commit b1bcbc1

Browse files
committed
fix: apply automatic clippy fixes and resolve type conversion issues
- Fix Cow<str> to Path conversions by using value.as_ref() - Remove unnecessary mut from variable declaration - Apply various automatic clippy fixes for redundant code
1 parent 62535fa commit b1bcbc1

File tree

10 files changed

+24
-28
lines changed

10 files changed

+24
-28
lines changed

sqlx-core/src/postgres/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<C: DerefMut<Target = PgConnection>> PgCopyIn<C> {
206206
let stream = &mut buf_stream.stream;
207207

208208
// ensures the buffer isn't left in an inconsistent state
209-
let mut guard = BufGuard(&mut buf_stream.wbuf);
209+
let guard = BufGuard(&mut buf_stream.wbuf);
210210

211211
let buf: &mut Vec<u8> = guard.0;
212212
buf.push(b'd'); // CopyData format code

sqlx-core/src/postgres/message/data_row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Decode<'_> for DataRow {
4242

4343
if let Ok(length) = u32::try_from(length) {
4444
values.push(Some(offset..(offset + length)));
45-
offset += length as u32;
45+
offset += length;
4646
} else {
4747
values.push(None);
4848
}

sqlx-core/src/postgres/options/parse.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ impl FromStr for PgConnectOptions {
5454
}
5555

5656
"sslrootcert" | "ssl-root-cert" | "ssl-ca" => {
57-
options = options.ssl_root_cert(&value);
57+
options = options.ssl_root_cert(value.as_ref());
5858
}
5959

60-
"sslcert" | "ssl-cert" => options = options.ssl_client_cert(&value),
60+
"sslcert" | "ssl-cert" => options = options.ssl_client_cert(value.as_ref()),
6161

62-
"sslkey" | "ssl-key" => options = options.ssl_client_key(&value),
62+
"sslkey" | "ssl-key" => options = options.ssl_client_key(value.as_ref()),
6363

6464
"statement-cache-capacity" => {
6565
options =
@@ -68,39 +68,39 @@ impl FromStr for PgConnectOptions {
6868

6969
"host" => {
7070
if value.starts_with("/") {
71-
options = options.socket(&value);
71+
options = options.socket(value.as_ref());
7272
} else {
73-
options = options.host(&value);
73+
options = options.host(value.as_ref());
7474
}
7575
}
7676

7777
"hostaddr" => {
7878
value.parse::<IpAddr>().map_err(Error::config)?;
79-
options = options.host(&value)
79+
options = options.host(value.as_ref())
8080
}
8181

8282
"port" => options = options.port(value.parse().map_err(Error::config)?),
8383

84-
"dbname" => options = options.database(&value),
84+
"dbname" => options = options.database(value.as_ref()),
8585

86-
"user" => options = options.username(&value),
86+
"user" => options = options.username(value.as_ref()),
8787

88-
"password" => options = options.password(&value),
88+
"password" => options = options.password(value.as_ref()),
8989

90-
"application_name" => options = options.application_name(&value),
90+
"application_name" => options = options.application_name(value.as_ref()),
9191

9292
"options" => {
9393
if let Some(options) = options.options.as_mut() {
9494
options.push(' ');
95-
options.push_str(&value);
95+
options.push_str(value.as_ref());
9696
} else {
9797
options.options = Some(value.to_string());
9898
}
9999
}
100100

101101
k if k.starts_with("options[") => {
102102
if let Some(key) = k.strip_prefix("options[").unwrap().strip_suffix(']') {
103-
options = options.options([(key, &value)]);
103+
options = options.options([(key, value.as_ref())]);
104104
}
105105
}
106106

sqlx-core/src/postgres/options/ssl_mode.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::str::FromStr;
55
///
66
/// It is used by the [`ssl_mode`](super::PgConnectOptions::ssl_mode) method.
77
#[derive(Debug, Clone, Copy)]
8+
#[derive(Default)]
89
pub enum PgSslMode {
910
/// Only try a non-SSL connection.
1011
Disable,
@@ -13,6 +14,7 @@ pub enum PgSslMode {
1314
Allow,
1415

1516
/// First try an SSL connection; if that fails, try a non-SSL connection.
17+
#[default]
1618
Prefer,
1719

1820
/// Only try an SSL connection. If a root CA file is present, verify the connection
@@ -28,11 +30,6 @@ pub enum PgSslMode {
2830
VerifyFull,
2931
}
3032

31-
impl Default for PgSslMode {
32-
fn default() -> Self {
33-
PgSslMode::Prefer
34-
}
35-
}
3633

3734
impl FromStr for PgSslMode {
3835
type Err = Error;

sqlx-core/src/postgres/statement.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ impl ColumnIndex<PgStatement<'_>> for &'_ str {
5353
.metadata
5454
.column_names
5555
.get(*self)
56-
.ok_or_else(|| Error::ColumnNotFound((*self).into()))
57-
.map(|v| *v)
56+
.ok_or_else(|| Error::ColumnNotFound((*self).into())).copied()
5857
}
5958
}
6059

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ where
9494
T: Encode<'q, Postgres> + Type<Postgres>,
9595
{
9696
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
97-
let type_info = if self.len() < 1 {
97+
let type_info = if self.is_empty() {
9898
T::type_info()
9999
} else {
100100
self[0].produces().unwrap_or_else(T::type_info)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl TryFrom<std::time::Duration> for PgInterval {
182182
/// This returns an error if there is a loss of precision using nanoseconds or if there is a
183183
/// microsecond overflow.
184184
fn try_from(value: std::time::Duration) -> Result<Self, BoxDynError> {
185-
if value.as_nanos() % 1000 != 0 {
185+
if !value.as_nanos().is_multiple_of(1000) {
186186
return Err("PostgreSQL `INTERVAL` does not support nanoseconds precision".into());
187187
}
188188

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl FromStr for PgLQueryVariant {
266266
let mut rev_iter = s.bytes().rev();
267267
let mut modifiers = PgLQueryVariantFlag::default();
268268

269-
while let Some(b) = rev_iter.next() {
269+
for b in rev_iter {
270270
match b {
271271
b'@' => modifiers.insert(PgLQueryVariantFlag::IN_CASE),
272272
b'*' => modifiers.insert(PgLQueryVariantFlag::ANY_END),
@@ -307,8 +307,8 @@ impl Display for PgLQueryLevel {
307307
PgLQueryLevel::Star(Some(at_least), _) => write!(f, "*{{{},}}", at_least),
308308
PgLQueryLevel::Star(_, Some(at_most)) => write!(f, "*{{,{}}}", at_most),
309309
PgLQueryLevel::Star(_, _) => write!(f, "*"),
310-
PgLQueryLevel::NonStar(variants) => write_variants(f, &variants, false),
311-
PgLQueryLevel::NotNonStar(variants) => write_variants(f, &variants, true),
310+
PgLQueryLevel::NonStar(variants) => write_variants(f, variants, false),
311+
PgLQueryLevel::NotNonStar(variants) => write_variants(f, variants, true),
312312
}
313313
}
314314
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ fn range_compatible<E: Type<Postgres>>(ty: &PgTypeInfo) -> bool {
518518
// we require the declared type to be a _range_ with an
519519
// element type that is acceptable
520520
if let PgTypeKind::Range(element) = &ty.kind() {
521-
return E::compatible(&element);
521+
return E::compatible(element);
522522
}
523523

524524
false

sqlx-core/src/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ where
293293
let mut f = self.mapper;
294294
Map {
295295
inner: self.inner,
296-
mapper: move |row| f(row).and_then(|o| g(o)),
296+
mapper: move |row| f(row).and_then(&mut g),
297297
}
298298
}
299299

0 commit comments

Comments
 (0)