Skip to content

Commit 98ad187

Browse files
lovasoacursoragent
andauthored
AI code cleanup: Address clippy warnings and add to gh actions (#31)
* Add clippy checks and suppress doctest warning Co-authored-by: contact <[email protected]> * Refactor: Add 'q lifetime bound to Execute trait This change adds the 'q lifetime bound to the Execute trait in various executor implementations. This ensures that the query parameters live long enough for the query to be executed, preventing potential lifetime issues. Co-authored-by: contact <[email protected]> * Refactor: Improve sqlx code quality and fix minor issues Co-authored-by: contact <[email protected]> * fix: resolve clippy warnings in pool/inner.rs - Fix non-binding let on future by spawning close() future - Replace map_or(false, ...) with is_some_and(...) - Remove needless borrow in Arc::clone() * fix: resolve additional clippy warnings - Fix let_underscore_future by explicitly dropping the future - Remove unused type parameter DB from deadline_as_timeout function * fix: resolve clippy warnings in query, io, and tls modules - Fix reference to reference pattern in query.rs - Remove redundant closure using and_then directly - Remove needless borrows in io/buf.rs and logger.rs - Replace iter().cloned().collect() with to_vec() for better performance - Use std::io::Error::other() instead of Error::new(ErrorKind::Other) * fix: resolve more clippy warnings - Remove reference patterns in query.rs match statements - Fix unneeded return statements in net/tls/mod.rs - Remove explicit deref in postgres/column.rs - Revert redundant closure fix that caused compilation error * fix: resolve auto-deref and other clippy warnings - Remove explicit derefs that would be done by auto-deref - Fix needless borrows in various modules - Replace is_digit(10) with is_ascii_digit() - Fix doc list indentation in postgres/copy.rs * fix: resolve redundant closures and more auto-deref warnings - Remove redundant closures in lquery and ltree types - Fix auto-deref issues in postgres options parser - Fix auto-deref issues in postgres type_info * 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 * fix: resolve remaining simple clippy warnings - Remove unused mut from variable declaration - Remove unused lifetime parameter - Remove legacy numeric constant import - Simplify boolean expression using De Morgan's law * fix: resolve large enum variant and naming warnings - Box the TlsStream variant to reduce enum size - Rename from_iter methods to avoid confusion with std trait - Update all pattern matches to handle boxed variant * Refactor: Improve TLS stream handling and add test script Co-authored-by: contact <[email protected]> * Checkpoint before follow-up message Co-authored-by: contact <[email protected]> * 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 * fix: more clippy warnings in sqlite and logger modules - Fix match_like_matches_macro by using is_some() in logger.rs - Fix needless_borrow warnings in sqlite/connection/execute.rs - Fix ptr_arg by using slice instead of Vec reference - Fix clone_on_copy by dereferencing instead of cloning - Fix needless_return by removing redundant return keyword - Fix explicit_counter_loop by using enumerate() * 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 * fix: clippy warnings for mysql and final sqlite modules - Fix unnecessary_cast in sqlite/statement/virtual.rs - Add is_empty() method to MySqlArguments to fix len_without_is_empty - Fix explicit_auto_deref in mysql/column.rs and mysql/options/parse.rs - Fix needless_borrows_for_generic_args in mysql/connection/auth.rs - Fix borrow_deref_ref in mysql/connection/auth.rs - Fix needless_borrow in mysql/connection/auth.rs and executor.rs - Remove unused lifetime in mysql/connection/executor.rs - Fix get_first by using first() instead of get(0) * fix: more clippy warnings in mysql modules - Fix explicit_auto_deref in mysql/options/parse.rs and mysql/transaction.rs - Replace manual Default impl with derive for MySqlSslMode - Add allow for enum_variant_names in AuthPlugin (breaking change to fix) - Fix get_first by using first() instead of get(0) - Fix unnecessary_cast by removing redundant casts - Fix map_clone by using copied() method in row and statement modules * fix: clippy warnings in mysql types and migrate modules - Fix let_and_return in mysql/types/float.rs - Fix needless_borrows_for_generic_args in chrono and time modules - Fix len_zero by using is_empty() - Fix unnecessary_cast by removing redundant type casts - Fix unwrap_or_default usage - Fix needless_borrow in json module - Fix needless_option_as_deref in value module - Fix get_first by using first() instead of get(0) - Fix needless_return in migrate module * fix: clippy warnings in mysql testing and mssql modules - Fix op_ref by using direct comparison in mysql/migrate.rs - Fix needless_borrows_for_generic_args in mysql/testing/mod.rs - Fix drop_non_drop by using let binding instead of drop - Fix single_char_add_str by using push() with char literal - Fix explicit_auto_deref in mssql/column.rs and establish.rs - Fix io_other_error by using std::io::Error::other() - Fix unnecessary_map_or by using is_some_and() - Fix unit_arg by using Default::default() - Add allow for let_unit_value due to platform differences * fix: more clippy warnings in mssql modules - Fix unit_arg by using () instead of Default::default() - Fix redundant_closure by using function reference directly - Fix while_let_on_iterator by using for loop - Fix explicit_auto_deref in mssql/options/parse.rs - Add allow for result_large_err in requested_packet_size - Fix needless_range_loop by iterating over slice directly - Add allow for ptr_arg where Vec-specific methods are used * fix: final clippy warnings in mssql modules - Fix unused_mut in mssql/io/buf_mut.rs - Fix useless_conversion by removing redundant .into() - Fix manual_div_ceil by using div_ceil method * fix: platform-specific return type for async-std in tls_prelogin_stream_wrapper - Return 0 for async-std and () for tokio in poll_read - Fixes compilation with runtime-async-std-rustls feature * Refactor: Remove unused blank lines and reorder imports Co-authored-by: contact <[email protected]> * fix: clippy warnings in tests and macros - Fix deprecated chrono DateTime::from_utc usage - Add workspace lint config to allow postgres_14 cfg - Fix dead code warnings in sqlx-macros query data - Fix needless_borrows_for_generic_args in sqlx-macros - Fix useless_conversion by removing redundant .into() - Fix useless_vec by using array instead of vec! in test * cargo fmt * fix: update type annotations for DateTime in MySQL tests - Change DateTime::from_naive_utc_and_offset to DateTime::<Utc>::from_naive_utc_and_offset in chrono tests * refactor: remove unused custom domain type and update imports in tests - Removed the unused RangeInclusive struct from derives.rs - Added #[allow(unused_imports)] to macros.rs and types.rs to suppress warnings * fix: correct error handling in native-tls downgrade message * refactor: streamline clippy checks in CI workflow - Removed clippy job and integrated checks into existing jobs for core, root, and all targets. - Added clippy checks for sqlite, postgres, mysql, mariadb, and mssql with specific features. - Enhanced CI workflow efficiency by consolidating clippy steps. * fix: update lint configurations and suppress unused import warnings in tests - Added 'cfg(postgres_9_6)' to the lint configuration in Cargo.toml. - Suppressed unused import warnings in various test files for better clarity and maintainability. - Adjusted assertions in MySQL tests for boolean values to use assert! macro. * fmt * chore: add unused import suppressions in test files - Included additional imports for Executor and Row in pool.rs and types.rs respectively. - Suppressed unused import warnings to enhance code clarity. * refactor: remove test_all_features.sh script and suppress unused import warnings - Deleted the test_all_features.sh script to streamline the testing process. - Added unused import suppressions in test_attr.rs and mssql.rs for improved code clarity. * refactor: rename from_label_iter to from_iter for consistency - Renamed the method from_label_iter to from_iter in PgLTree to align with naming conventions and improve clarity. --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent ef520b9 commit 98ad187

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+387
-349
lines changed

.github/workflows/sqlx.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- run: cargo fmt --all -- --check
1616

17+
1718
check:
1819
name: Check
1920
runs-on: ubuntu-22.04
@@ -40,6 +41,25 @@ jobs:
4041
--no-default-features
4142
--lib --tests
4243
--features offline,all-databases,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
44+
- name: Run clippy for core with all features
45+
run: |
46+
cargo clippy --manifest-path sqlx-core/Cargo.toml \
47+
--no-default-features \
48+
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }} \
49+
-- -D warnings
50+
- name: Run clippy for root with all features
51+
run: |
52+
cargo clippy \
53+
--no-default-features \
54+
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros \
55+
-- -D warnings
56+
- name: Run clippy for all targets
57+
run: |
58+
cargo clippy \
59+
--no-default-features \
60+
--all-targets \
61+
--features offline,all-databases,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }} \
62+
-- -D warnings
4363
4464
test:
4565
name: Unit Test
@@ -98,6 +118,7 @@ jobs:
98118
name: cargo-sqlx-${{ matrix.target }}
99119
path: ${{ matrix.bin }}
100120

121+
101122
sqlite:
102123
name: SQLite
103124
runs-on: ubuntu-22.04
@@ -110,6 +131,12 @@ jobs:
110131
- uses: actions/checkout@v4
111132
- run: mkdir /tmp/sqlite3-lib && wget -O /tmp/sqlite3-lib/ipaddr.so https://github.com/nalgeon/sqlean/releases/download/0.15.2/ipaddr.so
112133
- uses: Swatinem/rust-cache@v2
134+
- name: Run clippy for sqlite
135+
run: |
136+
cargo clippy \
137+
--no-default-features \
138+
--features sqlite,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros,migrate \
139+
-- -D warnings
113140
- run:
114141
cargo test
115142
--no-default-features
@@ -153,6 +180,15 @@ jobs:
153180
args: >
154181
--features postgres,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
155182
183+
- name: Run clippy for postgres
184+
run: |
185+
cargo clippy \
186+
--no-default-features \
187+
--features postgres,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros,migrate \
188+
-- -D warnings
189+
env:
190+
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}
191+
156192
- run: |
157193
docker compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_${{ matrix.postgres }} postgres_${{ matrix.postgres }}
158194
docker exec postgres_${{ matrix.postgres }} bash -c "until pg_isready; do sleep 1; done"
@@ -224,6 +260,13 @@ jobs:
224260
args: >
225261
--features mysql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
226262
263+
- name: Run clippy for mysql
264+
run: |
265+
cargo clippy \
266+
--no-default-features \
267+
--features mysql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros,migrate \
268+
-- -D warnings
269+
227270
- run: docker compose -f tests/docker-compose.yml run -d -p 3306:3306 mysql_${{ matrix.mysql }}
228271
- run: sleep 60
229272

@@ -275,6 +318,13 @@ jobs:
275318
args: >
276319
--features mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
277320
321+
- name: Run clippy for mariadb
322+
run: |
323+
cargo clippy \
324+
--no-default-features \
325+
--features mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros,migrate \
326+
-- -D warnings
327+
278328
- run: docker compose -f tests/docker-compose.yml run -d -p 3306:3306 mariadb_${{ matrix.mariadb }}
279329
- run: sleep 30
280330

@@ -315,6 +365,13 @@ jobs:
315365
args: >
316366
--features mssql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
317367
368+
- name: Run clippy for mssql
369+
run: |
370+
cargo clippy \
371+
--no-default-features \
372+
--features mssql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros,migrate \
373+
-- -D warnings
374+
318375
- run: docker compose -f tests/docker-compose.yml run -d -p 1433:1433 mssql_${{ matrix.mssql }}
319376
- run: sleep 80 # MSSQL takes a "bit" to startup
320377

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ members = [
1818
"examples/sqlite/todos",
1919
]
2020

21+
[workspace.lints.rust]
22+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(postgres_14)', 'cfg(postgres_9_6)'] }
23+
2124
[package]
2225
name = "sqlx-oldapi"
2326
version = "0.6.48"

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use futures_util::{StreamExt, TryStreamExt};
1414
impl<'c> Executor<'c> for &'c mut AnyConnection {
1515
type Database = Any;
1616

17-
fn fetch_many<'e, 'q: 'e, E: 'q>(
17+
fn fetch_many<'e, 'q: 'e, E>(
1818
self,
1919
mut query: E,
2020
) -> BoxStream<'e, Result<Either<AnyQueryResult, AnyRow>, Error>>
2121
where
2222
'c: 'e,
23-
E: Execute<'q, Self::Database>,
23+
E: Execute<'q, Self::Database> + 'q,
2424
{
2525
let arguments = query.take_arguments();
2626
let query = query.sql();
@@ -52,13 +52,13 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
5252
}
5353
}
5454

55-
fn fetch_optional<'e, 'q: 'e, E: 'q>(
55+
fn fetch_optional<'e, 'q: 'e, E>(
5656
self,
5757
mut query: E,
5858
) -> BoxFuture<'e, Result<Option<AnyRow>, Error>>
5959
where
6060
'c: 'e,
61-
E: Execute<'q, Self::Database>,
61+
E: Execute<'q, Self::Database> + 'q,
6262
{
6363
let arguments = query.take_arguments();
6464
let query = query.sql();

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/arguments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub trait IntoArguments<'q, DB: HasArguments<'q>>: Sized + Send {
2929

3030
// NOTE: required due to lack of lazy normalization
3131
#[allow(unused_macros)]
32+
#[allow(clippy::needless_doctest_main)]
3233
macro_rules! impl_into_arguments_for_arguments {
3334
($Arguments:path) => {
3435
impl<'q>

sqlx-core/src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub trait Connection: Send {
119119
{
120120
let options = url.parse();
121121

122-
Box::pin(async move { Ok(Self::connect_with(&options?).await?) })
122+
Box::pin(async move { Self::connect_with(&options?).await })
123123
}
124124

125125
/// Establish a new database connection with the provided options.

sqlx-core/src/executor.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ pub trait Executor<'c>: Send + Debug + Sized {
2626
type Database: Database;
2727

2828
/// Execute the query and return the total number of rows affected.
29-
fn execute<'e, 'q: 'e, E: 'q>(
29+
fn execute<'e, 'q: 'e, E>(
3030
self,
3131
query: E,
3232
) -> BoxFuture<'e, Result<<Self::Database as Database>::QueryResult, Error>>
3333
where
3434
'c: 'e,
35-
E: Execute<'q, Self::Database>,
35+
E: Execute<'q, Self::Database> + 'q,
3636
{
3737
self.execute_many(query).try_collect().boxed()
3838
}
3939

4040
/// Execute multiple queries and return the rows affected from each query, in a stream.
41-
fn execute_many<'e, 'q: 'e, E: 'q>(
41+
fn execute_many<'e, 'q: 'e, E>(
4242
self,
4343
query: E,
4444
) -> BoxStream<'e, Result<<Self::Database as Database>::QueryResult, Error>>
4545
where
4646
'c: 'e,
47-
E: Execute<'q, Self::Database>,
47+
E: Execute<'q, Self::Database> + 'q,
4848
{
4949
self.fetch_many(query)
5050
.try_filter_map(|step| async move {
@@ -57,13 +57,13 @@ pub trait Executor<'c>: Send + Debug + Sized {
5757
}
5858

5959
/// Execute the query and return the generated results as a stream.
60-
fn fetch<'e, 'q: 'e, E: 'q>(
60+
fn fetch<'e, 'q: 'e, E>(
6161
self,
6262
query: E,
6363
) -> BoxStream<'e, Result<<Self::Database as Database>::Row, Error>>
6464
where
6565
'c: 'e,
66-
E: Execute<'q, Self::Database>,
66+
E: Execute<'q, Self::Database> + 'q,
6767
{
6868
self.fetch_many(query)
6969
.try_filter_map(|step| async move {
@@ -77,7 +77,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
7777

7878
/// Execute multiple queries and return the generated results as a stream
7979
/// from each query, in a stream.
80-
fn fetch_many<'e, 'q: 'e, E: 'q>(
80+
fn fetch_many<'e, 'q: 'e, E>(
8181
self,
8282
query: E,
8383
) -> BoxStream<
@@ -89,28 +89,28 @@ pub trait Executor<'c>: Send + Debug + Sized {
8989
>
9090
where
9191
'c: 'e,
92-
E: Execute<'q, Self::Database>;
92+
E: Execute<'q, Self::Database> + 'q;
9393

9494
/// Execute the query and return all the generated results, collected into a [`Vec`].
95-
fn fetch_all<'e, 'q: 'e, E: 'q>(
95+
fn fetch_all<'e, 'q: 'e, E>(
9696
self,
9797
query: E,
9898
) -> BoxFuture<'e, Result<Vec<<Self::Database as Database>::Row>, Error>>
9999
where
100100
'c: 'e,
101-
E: Execute<'q, Self::Database>,
101+
E: Execute<'q, Self::Database> + 'q,
102102
{
103103
self.fetch(query).try_collect().boxed()
104104
}
105105

106106
/// Execute the query and returns exactly one row.
107-
fn fetch_one<'e, 'q: 'e, E: 'q>(
107+
fn fetch_one<'e, 'q: 'e, E>(
108108
self,
109109
query: E,
110110
) -> BoxFuture<'e, Result<<Self::Database as Database>::Row, Error>>
111111
where
112112
'c: 'e,
113-
E: Execute<'q, Self::Database>,
113+
E: Execute<'q, Self::Database> + 'q,
114114
{
115115
self.fetch_optional(query)
116116
.and_then(|row| match row {
@@ -121,13 +121,13 @@ pub trait Executor<'c>: Send + Debug + Sized {
121121
}
122122

123123
/// Execute the query and returns at most one row.
124-
fn fetch_optional<'e, 'q: 'e, E: 'q>(
124+
fn fetch_optional<'e, 'q: 'e, E>(
125125
self,
126126
query: E,
127127
) -> BoxFuture<'e, Result<Option<<Self::Database as Database>::Row>, Error>>
128128
where
129129
'c: 'e,
130-
E: Execute<'q, Self::Database>;
130+
E: Execute<'q, Self::Database> + 'q;
131131

132132
/// Prepare the SQL query to inspect the type information of its parameters
133133
/// and results.

sqlx-core/src/ext/ustr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ impl serde::Serialize for UStr {
103103
where
104104
S: serde::Serializer,
105105
{
106-
serializer.serialize_str(&self)
106+
serializer.serialize_str(self)
107107
}
108108
}

sqlx-core/src/io/buf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait BufExt: Buf {
2222
impl BufExt for Bytes {
2323
fn get_bytes_nul(&mut self) -> Result<Bytes, Error> {
2424
let nul =
25-
memchr(b'\0', &self).ok_or_else(|| err_protocol!("expected NUL in byte sequence"))?;
25+
memchr(b'\0', self).ok_or_else(|| err_protocol!("expected NUL in byte sequence"))?;
2626

2727
let v = self.slice(0..nul);
2828

@@ -40,7 +40,7 @@ impl BufExt for Bytes {
4040

4141
fn get_str_nul(&mut self) -> Result<String, Error> {
4242
self.get_bytes_nul().and_then(|bytes| {
43-
from_utf8(&*bytes)
43+
from_utf8(&bytes)
4444
.map(ToOwned::to_owned)
4545
.map_err(|err| err_protocol!("{}", err))
4646
})

0 commit comments

Comments
 (0)