Skip to content

Commit 0744636

Browse files
committed
fix: lots, *lots* more Clippy warnings
1 parent 1ea5b72 commit 0744636

File tree

15 files changed

+58
-65
lines changed

15 files changed

+58
-65
lines changed

examples/postgres/listen/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ from (
9898
) notifies(chan, payload)
9999
"#,
100100
)
101-
.bind(&COUNTER.fetch_add(1, Ordering::SeqCst))
102-
.bind(&COUNTER.fetch_add(1, Ordering::SeqCst))
103-
.bind(&COUNTER.fetch_add(1, Ordering::SeqCst))
101+
.bind(COUNTER.fetch_add(1, Ordering::SeqCst))
102+
.bind(COUNTER.fetch_add(1, Ordering::SeqCst))
103+
.bind(COUNTER.fetch_add(1, Ordering::SeqCst))
104104
.execute(pool)
105105
.await;
106106

sqlx-core/src/net/tls/tls_rustls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ where
138138
}
139139
} else {
140140
#[cfg(any(feature = "_tls-rustls-aws-lc-rs", feature = "_tls-rustls-ring-webpki"))]
141-
let cert_store = certs_from_webpki();
141+
let mut cert_store = certs_from_webpki();
142142
#[cfg(feature = "_tls-rustls-ring-native-roots")]
143143
let mut cert_store = certs_from_native_store();
144144

sqlx-core/src/pool/inner.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,15 @@ pub(super) fn is_beyond_max_lifetime<DB: Database>(
451451
options: &PoolOptions<DB>,
452452
) -> bool {
453453
options
454-
.max_lifetime.is_some_and(|max| live.created_at.elapsed() > max)
454+
.max_lifetime
455+
.is_some_and(|max| live.created_at.elapsed() > max)
455456
}
456457

457458
/// Returns `true` if the connection has exceeded `options.idle_timeout` if set, `false` otherwise.
458459
fn is_beyond_idle_timeout<DB: Database>(idle: &Idle<DB>, options: &PoolOptions<DB>) -> bool {
459460
options
460-
.idle_timeout.is_some_and(|timeout| idle.idle_since.elapsed() > timeout)
461+
.idle_timeout
462+
.is_some_and(|timeout| idle.idle_since.elapsed() > timeout)
461463
}
462464

463465
async fn check_idle_conn<DB: Database>(

sqlx-mysql/src/io/buf_mut.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,71 +45,71 @@ impl MySqlBufMutExt for Vec<u8> {
4545
#[test]
4646
fn test_encodes_int_lenenc_u8() {
4747
let mut buf = Vec::with_capacity(1024);
48-
buf.put_uint_lenenc(0xFA as u64);
48+
buf.put_uint_lenenc(0xFA_u64);
4949

5050
assert_eq!(&buf[..], b"\xFA");
5151
}
5252

5353
#[test]
5454
fn test_encodes_int_lenenc_u16() {
5555
let mut buf = Vec::with_capacity(1024);
56-
buf.put_uint_lenenc(std::u16::MAX as u64);
56+
buf.put_uint_lenenc(u16::MAX as u64);
5757

5858
assert_eq!(&buf[..], b"\xFC\xFF\xFF");
5959
}
6060

6161
#[test]
6262
fn test_encodes_int_lenenc_u24() {
6363
let mut buf = Vec::with_capacity(1024);
64-
buf.put_uint_lenenc(0xFF_FF_FF as u64);
64+
buf.put_uint_lenenc(0xFF_FF_FF_u64);
6565

6666
assert_eq!(&buf[..], b"\xFD\xFF\xFF\xFF");
6767
}
6868

6969
#[test]
7070
fn test_encodes_int_lenenc_u64() {
7171
let mut buf = Vec::with_capacity(1024);
72-
buf.put_uint_lenenc(std::u64::MAX);
72+
buf.put_uint_lenenc(u64::MAX);
7373

7474
assert_eq!(&buf[..], b"\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
7575
}
7676

7777
#[test]
7878
fn test_encodes_int_lenenc_fb() {
7979
let mut buf = Vec::with_capacity(1024);
80-
buf.put_uint_lenenc(0xFB as u64);
80+
buf.put_uint_lenenc(0xFB_u64);
8181

8282
assert_eq!(&buf[..], b"\xFC\xFB\x00");
8383
}
8484

8585
#[test]
8686
fn test_encodes_int_lenenc_fc() {
8787
let mut buf = Vec::with_capacity(1024);
88-
buf.put_uint_lenenc(0xFC as u64);
88+
buf.put_uint_lenenc(0xFC_u64);
8989

9090
assert_eq!(&buf[..], b"\xFC\xFC\x00");
9191
}
9292

9393
#[test]
9494
fn test_encodes_int_lenenc_fd() {
9595
let mut buf = Vec::with_capacity(1024);
96-
buf.put_uint_lenenc(0xFD as u64);
96+
buf.put_uint_lenenc(0xFD_u64);
9797

9898
assert_eq!(&buf[..], b"\xFC\xFD\x00");
9999
}
100100

101101
#[test]
102102
fn test_encodes_int_lenenc_fe() {
103103
let mut buf = Vec::with_capacity(1024);
104-
buf.put_uint_lenenc(0xFE as u64);
104+
buf.put_uint_lenenc(0xFE_u64);
105105

106106
assert_eq!(&buf[..], b"\xFC\xFE\x00");
107107
}
108108

109109
#[test]
110110
fn test_encodes_int_lenenc_ff() {
111111
let mut buf = Vec::with_capacity(1024);
112-
buf.put_uint_lenenc(0xFF as u64);
112+
buf.put_uint_lenenc(0xFF_u64);
113113

114114
assert_eq!(&buf[..], b"\xFC\xFF\x00");
115115
}

sqlx-postgres/src/advisory_lock.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'lock, C: AsMut<PgConnection>> PgAdvisoryLockGuard<'lock, C> {
362362
}
363363
}
364364

365-
impl<'lock, C: AsMut<PgConnection> + AsRef<PgConnection>> Deref for PgAdvisoryLockGuard<'lock, C> {
365+
impl<C: AsMut<PgConnection> + AsRef<PgConnection>> Deref for PgAdvisoryLockGuard<'_, C> {
366366
type Target = PgConnection;
367367

368368
fn deref(&self) -> &Self::Target {
@@ -376,16 +376,14 @@ impl<'lock, C: AsMut<PgConnection> + AsRef<PgConnection>> Deref for PgAdvisoryLo
376376
/// However, replacing the connection with a different one using, e.g. [`std::mem::replace()`]
377377
/// is a logic error and will cause a warning to be logged by the PostgreSQL server when this
378378
/// guard attempts to release the lock.
379-
impl<'lock, C: AsMut<PgConnection> + AsRef<PgConnection>> DerefMut
380-
for PgAdvisoryLockGuard<'lock, C>
381-
{
379+
impl<C: AsMut<PgConnection> + AsRef<PgConnection>> DerefMut for PgAdvisoryLockGuard<'_, C> {
382380
fn deref_mut(&mut self) -> &mut Self::Target {
383381
self.conn.as_mut().expect(NONE_ERR).as_mut()
384382
}
385383
}
386384

387-
impl<'lock, C: AsMut<PgConnection> + AsRef<PgConnection>> AsRef<PgConnection>
388-
for PgAdvisoryLockGuard<'lock, C>
385+
impl<C: AsMut<PgConnection> + AsRef<PgConnection>> AsRef<PgConnection>
386+
for PgAdvisoryLockGuard<'_, C>
389387
{
390388
fn as_ref(&self) -> &PgConnection {
391389
self.conn.as_ref().expect(NONE_ERR).as_ref()
@@ -398,7 +396,7 @@ impl<'lock, C: AsMut<PgConnection> + AsRef<PgConnection>> AsRef<PgConnection>
398396
/// However, replacing the connection with a different one using, e.g. [`std::mem::replace()`]
399397
/// is a logic error and will cause a warning to be logged by the PostgreSQL server when this
400398
/// guard attempts to release the lock.
401-
impl<'lock, C: AsMut<PgConnection>> AsMut<PgConnection> for PgAdvisoryLockGuard<'lock, C> {
399+
impl<C: AsMut<PgConnection>> AsMut<PgConnection> for PgAdvisoryLockGuard<'_, C> {
402400
fn as_mut(&mut self) -> &mut PgConnection {
403401
self.conn.as_mut().expect(NONE_ERR).as_mut()
404402
}
@@ -407,7 +405,7 @@ impl<'lock, C: AsMut<PgConnection>> AsMut<PgConnection> for PgAdvisoryLockGuard<
407405
/// Queues a `pg_advisory_unlock()` call on the wrapped connection which will be flushed
408406
/// to the server the next time it is used, or when it is returned to [`PgPool`][crate::PgPool]
409407
/// in the case of [`PoolConnection<Postgres>`][crate::pool::PoolConnection].
410-
impl<'lock, C: AsMut<PgConnection>> Drop for PgAdvisoryLockGuard<'lock, C> {
408+
impl<C: AsMut<PgConnection>> Drop for PgAdvisoryLockGuard<'_, C> {
411409
fn drop(&mut self) {
412410
if let Some(mut conn) = self.conn.take() {
413411
// Queue a simple query message to execute next time the connection is used.

sqlx-postgres/src/connection/executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl PgConnection {
159159
self.inner.pending_ready_for_query_count += 1;
160160
}
161161

162-
async fn get_or_prepare<'a>(
162+
async fn get_or_prepare(
163163
&mut self,
164164
sql: &str,
165165
parameters: &[PgTypeInfo],

sqlx-postgres/src/connection/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{PgConnectOptions, PgSslMode};
77

88
pub struct MaybeUpgradeTls<'a>(pub &'a PgConnectOptions);
99

10-
impl<'a> WithSocket for MaybeUpgradeTls<'a> {
10+
impl WithSocket for MaybeUpgradeTls<'_> {
1111
type Output = crate::Result<Box<dyn Socket>>;
1212

1313
async fn with_socket<S: Socket>(self, socket: S) -> Self::Output {

sqlx-postgres/src/listener.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,12 @@ fn build_listen_all_query(channels: impl IntoIterator<Item = impl AsRef<str>>) -
506506

507507
#[test]
508508
fn test_build_listen_all_query_with_single_channel() {
509-
let output = build_listen_all_query(&["test"]);
509+
let output = build_listen_all_query(["test"]);
510510
assert_eq!(output.as_str(), r#"LISTEN "test";"#);
511511
}
512512

513513
#[test]
514514
fn test_build_listen_all_query_with_multiple_channels() {
515-
let output = build_listen_all_query(&["channel.0", "channel.1"]);
515+
let output = build_listen_all_query(["channel.0", "channel.1"]);
516516
assert_eq!(output.as_str(), r#"LISTEN "channel.0";LISTEN "channel.1";"#);
517517
}

sqlx-postgres/src/message/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct Fields<'a> {
195195
offset: usize,
196196
}
197197

198-
impl<'a> Iterator for Fields<'a> {
198+
impl Iterator for Fields<'_> {
199199
type Item = (u8, Range<usize>);
200200

201201
fn next(&mut self) -> Option<Self::Item> {

sqlx-postgres/src/options/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn built_url_can_be_parsed() {
336336
let url = "postgres://username:p@ssw0rd@hostname:5432/database";
337337
let opts = PgConnectOptions::from_str(url).unwrap();
338338

339-
let parsed = PgConnectOptions::from_str(&opts.build_url().to_string());
339+
let parsed = PgConnectOptions::from_str(opts.build_url().as_ref());
340340

341341
assert!(parsed.is_ok());
342342
}

sqlx-postgres/src/types/bigdecimal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ fn sign_to_pg(sign: Sign) -> PgNumericSign {
213213
}
214214

215215
#[cfg(test)]
216-
mod bigdecimal_to_pgnumeric {
216+
#[allow(clippy::zero_prefixed_literal)] // Used for clarity
217+
mod tests {
217218
use super::{BigDecimal, PgNumeric, PgNumericSign};
218219
use std::convert::TryFrom;
219220

sqlx-postgres/src/types/interval.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ fn test_encode_interval() {
231231
microseconds: 0,
232232
};
233233
assert!(matches!(
234-
Encode::<Postgres>::encode(&interval, &mut buf),
234+
Encode::<Postgres>::encode(interval, &mut buf),
235235
Ok(IsNull::No)
236236
));
237237
assert_eq!(&**buf, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
@@ -243,7 +243,7 @@ fn test_encode_interval() {
243243
microseconds: 1_000,
244244
};
245245
assert!(matches!(
246-
Encode::<Postgres>::encode(&interval, &mut buf),
246+
Encode::<Postgres>::encode(interval, &mut buf),
247247
Ok(IsNull::No)
248248
));
249249
assert_eq!(&**buf, [0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 0, 0, 0, 0, 0, 0]);
@@ -255,7 +255,7 @@ fn test_encode_interval() {
255255
microseconds: 1_000_000,
256256
};
257257
assert!(matches!(
258-
Encode::<Postgres>::encode(&interval, &mut buf),
258+
Encode::<Postgres>::encode(interval, &mut buf),
259259
Ok(IsNull::No)
260260
));
261261
assert_eq!(&**buf, [0, 0, 0, 0, 0, 15, 66, 64, 0, 0, 0, 0, 0, 0, 0, 0]);
@@ -267,7 +267,7 @@ fn test_encode_interval() {
267267
microseconds: 3_600_000_000,
268268
};
269269
assert!(matches!(
270-
Encode::<Postgres>::encode(&interval, &mut buf),
270+
Encode::<Postgres>::encode(interval, &mut buf),
271271
Ok(IsNull::No)
272272
));
273273
assert_eq!(
@@ -282,7 +282,7 @@ fn test_encode_interval() {
282282
microseconds: 0,
283283
};
284284
assert!(matches!(
285-
Encode::<Postgres>::encode(&interval, &mut buf),
285+
Encode::<Postgres>::encode(interval, &mut buf),
286286
Ok(IsNull::No)
287287
));
288288
assert_eq!(&**buf, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]);
@@ -294,7 +294,7 @@ fn test_encode_interval() {
294294
microseconds: 0,
295295
};
296296
assert!(matches!(
297-
Encode::<Postgres>::encode(&interval, &mut buf),
297+
Encode::<Postgres>::encode(interval, &mut buf),
298298
Ok(IsNull::No)
299299
));
300300
assert_eq!(&**buf, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);

sqlx-postgres/src/types/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl PgHasArrayType for JsonRawValue {
5454
}
5555
}
5656

57-
impl<'q, T> Encode<'q, Postgres> for Json<T>
57+
impl<T> Encode<'_, Postgres> for Json<T>
5858
where
5959
T: Serialize,
6060
{

0 commit comments

Comments
 (0)