Skip to content

Commit 2d30b57

Browse files
committed
fix: more clippy warnings in sqlite modules
- Fix unused_mut in sqlite/connection/execute.rs - Fix manual_inspect by using inspect instead of map - Fix derivable_impls by deriving Default for sqlite option enums - Fix map_clone by using copied() method - Fix legacy_numeric_constants by using i32::MAX instead of importing
1 parent cfd6713 commit 2d30b57

File tree

8 files changed

+13
-30
lines changed

8 files changed

+13
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Iterator for ExecuteIter<'_> {
6868

6969
fn next(&mut self) -> Option<Self::Item> {
7070
let statement = if self.goto_next {
71-
let mut statement = match self.statement.prepare_next(self.handle) {
71+
let statement = match self.statement.prepare_next(self.handle) {
7272
Ok(Some(statement)) => statement,
7373
Ok(None) => return None,
7474
Err(e) => return Some(Err(e)),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ impl ConnectionWorker {
124124
for cmd in command_rx {
125125
match cmd {
126126
Command::Prepare { query, tx } => {
127-
tx.send(prepare(&mut conn, &query).map(|prepared| {
127+
tx.send(prepare(&mut conn, &query).inspect(|_| {
128128
update_cached_statements_size(
129129
&conn,
130130
&shared.cached_statements_size,
131131
);
132-
prepared
133132
}))
134133
.ok();
135134
}

sqlx-core/src/sqlite/options/auto_vacuum.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::error::Error;
22
use std::str::FromStr;
33

4-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
55
pub enum SqliteAutoVacuum {
6+
#[default]
67
None,
78
Full,
89
Incremental,
@@ -18,11 +19,6 @@ impl SqliteAutoVacuum {
1819
}
1920
}
2021

21-
impl Default for SqliteAutoVacuum {
22-
fn default() -> Self {
23-
SqliteAutoVacuum::None
24-
}
25-
}
2622

2723
impl FromStr for SqliteAutoVacuum {
2824
type Err = Error;

sqlx-core/src/sqlite/options/journal_mode.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use std::str::FromStr;
44
/// Refer to [SQLite documentation] for the meaning of the database journaling mode.
55
///
66
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_journal_mode
7-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
88
pub enum SqliteJournalMode {
99
Delete,
1010
Truncate,
1111
Persist,
1212
Memory,
13+
#[default]
1314
Wal,
1415
Off,
1516
}
@@ -27,11 +28,6 @@ impl SqliteJournalMode {
2728
}
2829
}
2930

30-
impl Default for SqliteJournalMode {
31-
fn default() -> Self {
32-
SqliteJournalMode::Wal
33-
}
34-
}
3531

3632
impl FromStr for SqliteJournalMode {
3733
type Err = Error;

sqlx-core/src/sqlite/options/locking_mode.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use std::str::FromStr;
44
/// Refer to [SQLite documentation] for the meaning of the connection locking mode.
55
///
66
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_locking_mode
7-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
88
pub enum SqliteLockingMode {
9+
#[default]
910
Normal,
1011
Exclusive,
1112
}
@@ -19,11 +20,6 @@ impl SqliteLockingMode {
1920
}
2021
}
2122

22-
impl Default for SqliteLockingMode {
23-
fn default() -> Self {
24-
SqliteLockingMode::Normal
25-
}
26-
}
2723

2824
impl FromStr for SqliteLockingMode {
2925
type Err = Error;

sqlx-core/src/sqlite/options/synchronous.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use std::str::FromStr;
44
/// Refer to [SQLite documentation] for the meaning of various synchronous settings.
55
///
66
/// [SQLite documentation]: https://www.sqlite.org/pragma.html#pragma_synchronous
7-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
88
pub enum SqliteSynchronous {
99
Off,
1010
Normal,
11+
#[default]
1112
Full,
1213
Extra,
1314
}
@@ -23,11 +24,6 @@ impl SqliteSynchronous {
2324
}
2425
}
2526

26-
impl Default for SqliteSynchronous {
27-
fn default() -> Self {
28-
SqliteSynchronous::Full
29-
}
30-
}
3127

3228
impl FromStr for SqliteSynchronous {
3329
type Err = Error;

sqlx-core/src/sqlite/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl ColumnIndex<SqliteRow> for &'_ str {
7474
fn index(&self, row: &SqliteRow) -> Result<usize, Error> {
7575
row.column_names
7676
.get(*self)
77+
.copied()
7778
.ok_or_else(|| Error::ColumnNotFound((*self).into()))
78-
.map(|v| *v)
7979
}
8080
}
8181

sqlx-core/src/sqlite/statement/virtual.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use smallvec::SmallVec;
1414
use std::os::raw::c_char;
1515
use std::ptr::{null, null_mut, NonNull};
1616
use std::sync::Arc;
17-
use std::{cmp, i32};
17+
use std::cmp;
1818

1919
// A virtual statement consists of *zero* or more raw SQLite3 statements. We chop up a SQL statement
2020
// on `;` to support multiple statements in one query.
@@ -72,7 +72,7 @@ impl VirtualStatement {
7272
}
7373
}
7474

75-
if query.len() > i32::max_value() as usize {
75+
if query.len() > i32::MAX as usize {
7676
return Err(err_protocol!(
7777
"query string must be smaller than {} bytes",
7878
i32::MAX

0 commit comments

Comments
 (0)