Skip to content

Commit 3aff977

Browse files
committed
fix: lots of new Clippy warnings
1 parent 0760ee5 commit 3aff977

File tree

26 files changed

+55
-63
lines changed

26 files changed

+55
-63
lines changed

benches/sqlite/describe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use criterion::Criterion;
33
use criterion::{criterion_group, criterion_main};
44

55
use sqlx::sqlite::{Sqlite, SqliteConnection};
6-
use sqlx::{Connection, Executor};
6+
use sqlx::Executor;
77
use sqlx_test::new;
88

99
// Here we have an async function to benchmark

sqlx-macros-core/src/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub(crate) fn resolve_path(path: impl AsRef<Path>, err_span: Span) -> syn::Resul
1515
// requires `proc_macro::SourceFile::path()` to be stable
1616
// https://github.com/rust-lang/rust/issues/54725
1717
if path.is_relative()
18-
&& !path
18+
&& path
1919
.parent()
20-
.map_or(false, |parent| !parent.as_os_str().is_empty())
20+
.is_none_or(|parent| parent.as_os_str().is_empty())
2121
{
2222
return Err(syn::Error::new(
2323
err_span,

sqlx-macros-core/src/test_attr.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,9 @@ fn parse_args(attr_args: AttributeArgs) -> syn::Result<Args> {
246246

247247
fn recurse_lit_lookup(expr: Expr) -> Option<Lit> {
248248
match expr {
249-
Expr::Lit(syn::ExprLit { lit, .. }) => {
250-
return Some(lit);
251-
}
252-
Expr::Group(syn::ExprGroup { expr, .. }) => {
253-
return recurse_lit_lookup(*expr);
254-
}
255-
_ => return None,
249+
Expr::Lit(syn::ExprLit { lit, .. }) => Some(lit),
250+
Expr::Group(syn::ExprGroup { expr, .. }) => recurse_lit_lookup(*expr),
251+
_ => None,
256252
}
257253
}
258254

sqlx-mysql/src/connection/establish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> DoHandshake<'a> {
186186
}
187187
}
188188

189-
impl<'a> WithSocket for DoHandshake<'a> {
189+
impl WithSocket for DoHandshake<'_> {
190190
type Output = Result<MySqlStream, Error>;
191191

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

sqlx-mysql/src/connection/executor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use futures_util::TryStreamExt;
2525
use std::{borrow::Cow, pin::pin, sync::Arc};
2626

2727
impl MySqlConnection {
28-
async fn prepare_statement<'c>(
28+
async fn prepare_statement(
2929
&mut self,
3030
sql: &str,
3131
) -> Result<(u32, MySqlStatementMetadata), Error> {
@@ -72,7 +72,7 @@ impl MySqlConnection {
7272
Ok((id, metadata))
7373
}
7474

75-
async fn get_or_prepare_statement<'c>(
75+
async fn get_or_prepare_statement(
7676
&mut self,
7777
sql: &str,
7878
) -> Result<(u32, MySqlStatementMetadata), Error> {

sqlx-mysql/src/protocol/statement/execute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct Execute<'q> {
1111
pub arguments: &'q MySqlArguments,
1212
}
1313

14-
impl<'q> ProtocolEncode<'_, Capabilities> for Execute<'q> {
14+
impl ProtocolEncode<'_, Capabilities> for Execute<'_> {
1515
fn encode_with(&self, buf: &mut Vec<u8>, _: Capabilities) -> Result<(), crate::Error> {
1616
buf.push(0x17); // COM_STMT_EXECUTE
1717
buf.extend(&self.statement.to_le_bytes());

sqlx-mysql/src/types/text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<T> Type<MySql> for Text<T> {
1616
}
1717
}
1818

19-
impl<'q, T> Encode<'q, MySql> for Text<T>
19+
impl<T> Encode<'_, MySql> for Text<T>
2020
where
2121
T: Display,
2222
{

sqlx-postgres/src/types/cube.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'r> Decode<'r, Postgres> for PgCube {
7171
}
7272
}
7373

74-
impl<'q> Encode<'q, Postgres> for PgCube {
74+
impl Encode<'_, Postgres> for PgCube {
7575
fn produces(&self) -> Option<PgTypeInfo> {
7676
Some(PgTypeInfo::with_name("cube"))
7777
}

sqlx-postgres/src/types/geometry/box.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'r> Decode<'r, Postgres> for PgBox {
5656
}
5757
}
5858

59-
impl<'q> Encode<'q, Postgres> for PgBox {
59+
impl Encode<'_, Postgres> for PgBox {
6060
fn produces(&self) -> Option<PgTypeInfo> {
6161
Some(PgTypeInfo::with_name("box"))
6262
}

sqlx-postgres/src/types/geometry/circle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'r> Decode<'r, Postgres> for PgCircle {
5454
}
5555
}
5656

57-
impl<'q> Encode<'q, Postgres> for PgCircle {
57+
impl Encode<'_, Postgres> for PgCircle {
5858
fn produces(&self) -> Option<PgTypeInfo> {
5959
Some(PgTypeInfo::with_name("circle"))
6060
}

sqlx-postgres/src/types/geometry/line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'r> Decode<'r, Postgres> for PgLine {
4747
}
4848
}
4949

50-
impl<'q> Encode<'q, Postgres> for PgLine {
50+
impl Encode<'_, Postgres> for PgLine {
5151
fn produces(&self) -> Option<PgTypeInfo> {
5252
Some(PgTypeInfo::with_name("line"))
5353
}

sqlx-postgres/src/types/geometry/line_segment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'r> Decode<'r, Postgres> for PgLSeg {
5757
}
5858
}
5959

60-
impl<'q> Encode<'q, Postgres> for PgLSeg {
60+
impl Encode<'_, Postgres> for PgLSeg {
6161
fn produces(&self) -> Option<PgTypeInfo> {
6262
Some(PgTypeInfo::with_name("lseg"))
6363
}

sqlx-postgres/src/types/geometry/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'r> Decode<'r, Postgres> for PgPath {
6464
}
6565
}
6666

67-
impl<'q> Encode<'q, Postgres> for PgPath {
67+
impl Encode<'_, Postgres> for PgPath {
6868
fn produces(&self) -> Option<PgTypeInfo> {
6969
Some(PgTypeInfo::with_name("path"))
7070
}

sqlx-postgres/src/types/geometry/point.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'r> Decode<'r, Postgres> for PgPoint {
5050
}
5151
}
5252

53-
impl<'q> Encode<'q, Postgres> for PgPoint {
53+
impl Encode<'_, Postgres> for PgPoint {
5454
fn produces(&self) -> Option<PgTypeInfo> {
5555
Some(PgTypeInfo::with_name("point"))
5656
}

sqlx-postgres/src/types/geometry/polygon.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'r> Decode<'r, Postgres> for PgPolygon {
6363
}
6464
}
6565

66-
impl<'q> Encode<'q, Postgres> for PgPolygon {
66+
impl Encode<'_, Postgres> for PgPolygon {
6767
fn produces(&self) -> Option<PgTypeInfo> {
6868
Some(PgTypeInfo::with_name("polygon"))
6969
}

sqlx-sqlite/src/connection/intmap.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ impl<V> IntMap<V> {
2424
}
2525

2626
pub(crate) fn expand(&mut self, size: i64) -> usize {
27-
let idx = size.try_into().expect("negative column index unsupported");
28-
while self.0.len() <= idx {
29-
self.0.push(None);
27+
let idx = usize::try_from(size).expect("negative column index unsupported");
28+
if idx >= self.0.len() {
29+
let new_len = idx.checked_add(1).expect("idx + 1 overflowed");
30+
31+
self.0.resize_with(new_len, || None);
3032
}
3133
idx
3234
}
@@ -95,15 +97,9 @@ impl<V> IntMap<V> {
9597
}
9698

9799
impl<V: Default> IntMap<V> {
98-
pub(crate) fn get_mut_or_default<'a>(&'a mut self, idx: &i64) -> &'a mut V {
100+
pub(crate) fn get_mut_or_default(&mut self, idx: &i64) -> &mut V {
99101
let idx: usize = self.expand(*idx);
100-
101-
let item: &mut Option<V> = &mut self.0[idx];
102-
if item.is_none() {
103-
*item = Some(V::default());
104-
}
105-
106-
return self.0[idx].as_mut().unwrap();
102+
self.0[idx].get_or_insert_default()
107103
}
108104
}
109105

sqlx-sqlite/src/connection/worker.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ impl ConnectionWorker {
145145
let _guard = span.enter();
146146
match cmd {
147147
Command::Prepare { query, tx } => {
148-
tx.send(prepare(&mut conn, &query).map(|prepared| {
149-
update_cached_statements_size(
150-
&conn,
151-
&shared.cached_statements_size,
152-
);
153-
prepared
154-
}))
155-
.ok();
148+
tx.send(prepare(&mut conn, &query)).ok();
149+
150+
// This may issue an unnecessary write on failure,
151+
// but it doesn't matter in the grand scheme of things.
152+
update_cached_statements_size(
153+
&conn,
154+
&shared.cached_statements_size,
155+
);
156156
}
157157
Command::Describe { query, tx } => {
158158
tx.send(describe(&mut conn, &query)).ok();

sqlx-sqlite/src/logger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl<'q, R: Debug, S: Debug + DebugDiff, P: Debug> QueryPlanLogger<'q, R, S, P>
436436
}
437437
}
438438

439-
impl<'q, R: Debug, S: Debug + DebugDiff, P: Debug> Drop for QueryPlanLogger<'q, R, S, P> {
439+
impl<R: Debug, S: Debug + DebugDiff, P: Debug> Drop for QueryPlanLogger<'_, R, S, P> {
440440
fn drop(&mut self) {
441441
self.finish();
442442
}

sqlx-sqlite/src/value.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub(crate) struct ValueHandle<'a> {
108108
}
109109

110110
// SAFE: only protected value objects are stored in SqliteValue
111-
unsafe impl<'a> Send for ValueHandle<'a> {}
112-
unsafe impl<'a> Sync for ValueHandle<'a> {}
111+
unsafe impl Send for ValueHandle<'_> {}
112+
unsafe impl Sync for ValueHandle<'_> {}
113113

114114
impl ValueHandle<'static> {
115115
fn new_owned(value: NonNull<sqlite3_value>, type_info: SqliteTypeInfo) -> Self {
@@ -122,7 +122,7 @@ impl ValueHandle<'static> {
122122
}
123123
}
124124

125-
impl<'a> ValueHandle<'a> {
125+
impl ValueHandle<'_> {
126126
fn new_borrowed(value: NonNull<sqlite3_value>, type_info: SqliteTypeInfo) -> Self {
127127
Self {
128128
value,
@@ -185,7 +185,7 @@ impl<'a> ValueHandle<'a> {
185185
}
186186
}
187187

188-
impl<'a> Drop for ValueHandle<'a> {
188+
impl Drop for ValueHandle<'_> {
189189
fn drop(&mut self) {
190190
if self.free_on_drop {
191191
unsafe {

tests/mysql/mysql.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ async fn test_shrink_buffers() -> anyhow::Result<()> {
580580
conn.shrink_buffers();
581581

582582
let ret: i64 = sqlx::query_scalar("SELECT ?")
583-
.bind(&12345678i64)
583+
.bind(12345678i64)
584584
.fetch_one(&mut conn)
585585
.await?;
586586

tests/mysql/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ CREATE TEMPORARY TABLE with_bits (
316316
.await?;
317317

318318
sqlx::query("INSERT INTO with_bits (value_1, value_n) VALUES (?, ?)")
319-
.bind(&1_u8)
320-
.bind(&510202_u32)
319+
.bind(1_u8)
320+
.bind(510202_u32)
321321
.execute(&mut conn)
322322
.await?;
323323

tests/postgres/query_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn test_build() {
5555
let query = qb.build();
5656

5757
assert_eq!(query.sql(), "SELECT * FROM users WHERE id = $1");
58-
assert_eq!(Execute::persistent(&query), true);
58+
assert!(Execute::persistent(&query));
5959
}
6060

6161
#[test]

tests/postgres/test-attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async fn it_gets_comments(pool: PgPool) -> sqlx::Result<()> {
158158
let post_1_comments: Vec<String> = sqlx::query_scalar(
159159
"SELECT content FROM comment WHERE post_id = $1::uuid ORDER BY created_at",
160160
)
161-
.bind(&"252c1d98-a9b0-4f18-8298-e59058bdfe16")
161+
.bind("252c1d98-a9b0-4f18-8298-e59058bdfe16")
162162
.fetch_all(&pool)
163163
.await?;
164164

@@ -170,7 +170,7 @@ async fn it_gets_comments(pool: PgPool) -> sqlx::Result<()> {
170170
let post_2_comments: Vec<String> = sqlx::query_scalar(
171171
"SELECT content FROM comment WHERE post_id = $1::uuid ORDER BY created_at",
172172
)
173-
.bind(&"844265f7-2472-4689-9a2e-b21f40dbf401")
173+
.bind("844265f7-2472-4689-9a2e-b21f40dbf401")
174174
.fetch_all(&pool)
175175
.await?;
176176

tests/sqlite/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sqlx::{Any, Sqlite};
1+
use sqlx::Any;
22
use sqlx_test::new;
33

44
#[sqlx_macros::test]

tests/sqlite/sqlite.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ async fn issue_1467() -> anyhow::Result<()> {
639639

640640
// Random seed:
641641
let seed: [u8; 32] = rand::random();
642-
println!("RNG seed: {}", hex::encode(&seed));
642+
println!("RNG seed: {}", hex::encode(seed));
643643

644644
// Pre-determined seed:
645645
// let mut seed: [u8; 32] = [0u8; 32];
@@ -734,7 +734,7 @@ async fn test_query_with_progress_handler() -> anyhow::Result<()> {
734734
let mut conn = new::<Sqlite>().await?;
735735

736736
// Using this string as a canary to ensure the callback doesn't get called with the wrong data pointer.
737-
let state = format!("test");
737+
let state = "test".to_string();
738738
conn.lock_handle().await?.set_progress_handler(1, move || {
739739
assert_eq!(state, "test");
740740
false
@@ -802,7 +802,7 @@ async fn test_query_with_update_hook() -> anyhow::Result<()> {
802802
let mut conn = new::<Sqlite>().await?;
803803
static CALLED: AtomicBool = AtomicBool::new(false);
804804
// Using this string as a canary to ensure the callback doesn't get called with the wrong data pointer.
805-
let state = format!("test");
805+
let state = "test".to_string();
806806
conn.lock_handle().await?.set_update_hook(move |result| {
807807
assert_eq!(state, "test");
808808
assert_eq!(result.operation, SqliteOperation::Insert);
@@ -858,7 +858,7 @@ async fn test_query_with_commit_hook() -> anyhow::Result<()> {
858858
let mut conn = new::<Sqlite>().await?;
859859
static CALLED: AtomicBool = AtomicBool::new(false);
860860
// Using this string as a canary to ensure the callback doesn't get called with the wrong data pointer.
861-
let state = format!("test");
861+
let state = "test".to_string();
862862
conn.lock_handle().await?.set_commit_hook(move || {
863863
CALLED.store(true, Ordering::Relaxed);
864864
assert_eq!(state, "test");
@@ -920,7 +920,7 @@ async fn test_query_with_rollback_hook() -> anyhow::Result<()> {
920920
let mut conn = new::<Sqlite>().await?;
921921

922922
// Using this string as a canary to ensure the callback doesn't get called with the wrong data pointer.
923-
let state = format!("test");
923+
let state = "test".to_string();
924924
static CALLED: AtomicBool = AtomicBool::new(false);
925925
conn.lock_handle().await?.set_rollback_hook(move || {
926926
assert_eq!(state, "test");
@@ -977,7 +977,7 @@ async fn test_query_with_preupdate_hook_insert() -> anyhow::Result<()> {
977977
let mut conn = new::<Sqlite>().await?;
978978
static CALLED: AtomicBool = AtomicBool::new(false);
979979
// Using this string as a canary to ensure the callback doesn't get called with the wrong data pointer.
980-
let state = format!("test");
980+
let state = "test".to_string();
981981
conn.lock_handle().await?.set_preupdate_hook({
982982
move |result| {
983983
assert_eq!(state, "test");
@@ -1030,7 +1030,7 @@ async fn test_query_with_preupdate_hook_delete() -> anyhow::Result<()> {
10301030
.await?;
10311031
static CALLED: AtomicBool = AtomicBool::new(false);
10321032
// Using this string as a canary to ensure the callback doesn't get called with the wrong data pointer.
1033-
let state = format!("test");
1033+
let state = "test".to_string();
10341034
conn.lock_handle().await?.set_preupdate_hook(move |result| {
10351035
assert_eq!(state, "test");
10361036
assert_eq!(result.operation, SqliteOperation::Delete);
@@ -1077,7 +1077,7 @@ async fn test_query_with_preupdate_hook_update() -> anyhow::Result<()> {
10771077
static CALLED: AtomicBool = AtomicBool::new(false);
10781078
let sqlite_value_stored: Arc<std::sync::Mutex<Option<_>>> = Default::default();
10791079
// Using this string as a canary to ensure the callback doesn't get called with the wrong data pointer.
1080-
let state = format!("test");
1080+
let state = "test".to_string();
10811081
conn.lock_handle().await?.set_preupdate_hook({
10821082
let sqlite_value_stored = sqlite_value_stored.clone();
10831083
move |result| {

tests/sqlite/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mod json_tests {
8888
.fetch_one(&mut conn)
8989
.await?;
9090

91-
assert_eq!(true, value);
91+
assert!(value);
9292

9393
Ok(())
9494
}

0 commit comments

Comments
 (0)