Skip to content

Conversation

@lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Sep 16, 2025

Add Clippy CI workflow with a feature matrix and fix numerous Clippy warnings across the workspace.

The Clippy workflow runs for multiple feature combinations per package to ensure no warnings are introduced under various configurations, specifically addressing concerns about feature-gated code and unused imports.


Open in Cursor Open in Web

This commit makes several improvements including:
- Using `try_into` for safer type conversions from `i32` to `usize` and `c_int`.
- Replacing `&*` with direct dereferencing for string slices.
- Adding a clippy workflow to catch potential issues.
- Minor refactoring in various modules for clarity and consistency.

Co-authored-by: contact <[email protected]>
@cursor
Copy link

cursor bot commented Sep 16, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 13 commits September 16, 2025 12:57
…td: drop unused imports; pg options: adjust AsRef where needed
This commit includes several refactorings and improvements across sqlx-core and sqlx-macros. Key changes include:

- **sqlx-core:**
    - Added `#[cfg(feature = "sqlite")]` guards to `DebugFn` and its implementations to conditionally compile them only when the SQLite feature is enabled.
    - Removed unused `write` method from `buf_stream.rs` and added `#[allow(dead_code)]` to other unused methods.
    - Derived `Default` for `MySqlSslMode` and removed manual implementation.
    - Added `#[allow(dead_code)]` to `warnings` field in `EofPacket`.
    - Improved `f32` decoding for MySQL to clamp values to the `f32` range before casting.
    - Corrected `is_null` implementation in `mysql/value.rs` to use `self.value` directly.
    - Added `#[allow(dead_code)]` to `local_addr` in `net/socket.rs`.
    - Fixed potential issues with TLS stream upgrading and downgrading in `net/tls/mod.rs`, including adding `#[allow(dead_code)]` to `downgrade`.
    - Removed generic `DB: Database` from `deadline_as_timeout` in `pool/inner.rs` and `pool/mod.rs` as it was unused.

- **sqlx-macros:**
    - Wrapped `Type` in `Box` for `RecordType::Given` and `ColumnTypeOverride::Exact` to avoid potential stack overflows with deeply nested types.
    - Corrected the `migrations_path` resolution in `test_attr.rs` to use the span of the input signature.
    - Added `#[allow(dead_code)]` to `Args` and `MigrationsOpt` structs in `test_attr.rs`.
    - Fixed a minor formatting issue in the documentation for `query!()`.

Co-authored-by: contact <[email protected]>
@lovasoa
Copy link
Collaborator Author

lovasoa commented Sep 16, 2025

@cursoragent

    Checking sqlx-core-oldapi v0.6.48 (/home/runner/work/sqlx-oldapi/sqlx-oldapi/sqlx-core)
error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
  --> sqlx-core/src/postgres/connection/executor.rs:50:17
   |
50 |     conn.stream.write(Parse {
   |     ------------^^^^^
   |
  ::: sqlx-core/src/postgres/connection/stream.rs:25:1
   |
25 | pub struct PgStream {
   | ------------------- method `write` not found for this struct
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
   |
 1 + use sqlx_rt_oldapi::AsyncWriteExt;
   |
help: there is a method `write_i8` with a similar name
   |
50 |     conn.stream.write_i8(Parse {
   |                      +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
  --> sqlx-core/src/postgres/connection/executor.rs:58:21
   |
58 |         conn.stream.write(message::Describe::Statement(id));
   |                     ^^^^^
   |
  ::: sqlx-core/src/postgres/connection/stream.rs:25:1
   |
25 | pub struct PgStream {
   | ------------------- method `write` not found for this struct
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
   |
 1 + use sqlx_rt_oldapi::AsyncWriteExt;
   |
help: there is a method `write_i8` with a similar name
   |
58 |         conn.stream.write_i8(message::Describe::Statement(id));
   |                          +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/executor.rs:181:29
    |
181 |                 self.stream.write(Close::Statement(id));
    |                             ^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
181 |                 self.stream.write_i8(Close::Statement(id));
    |                                  +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/executor.rs:225:25
    |
225 |             self.stream.write(Bind {
    |             ------------^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
225 |             self.stream.write_i8(Bind {
    |                              +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/executor.rs:237:25
    |
237 |             self.stream.write(message::Execute {
    |             ------------^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
237 |             self.stream.write_i8(message::Execute {
    |                              +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/executor.rs:250:25
    |
250 |             self.stream.write(message::Close::Portal(None));
    |                         ^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
250 |             self.stream.write_i8(message::Close::Portal(None));
    |                              +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/executor.rs:263:25
    |
263 |             self.stream.write(Query(query));
    |                         ^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
263 |             self.stream.write_i8(Query(query));
    |                              +++

error[E0599]: no method named `write` found for mutable reference `&mut postgres::connection::stream::PgStream` in the current scope
  --> sqlx-core/src/postgres/connection/stream.rs:59:14
   |
59 |         self.write(message);
   |              ^^^^^
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
   |
 1 + use sqlx_rt_oldapi::AsyncWriteExt;
   |
help: there is a method `write_i8` with a similar name
   |
59 |         self.write_i8(message);
   |                   +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/executor.rs:157:21
    |
157 |         self.stream.write(message::Sync);
    |                     ^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
157 |         self.stream.write_i8(message::Sync);
    |                          +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/mod.rs:115:21
    |
115 |         self.stream.write(Query(query));
    |                     ^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
115 |         self.stream.write_i8(Query(query));
    |                          +++

error[E0599]: no method named `write` found for struct `postgres::connection::stream::PgStream` in the current scope
   --> sqlx-core/src/postgres/connection/mod.rs:183:29
    |
183 |                 self.stream.write(Close::Statement(id));
    |                             ^^^^^
    |
   ::: sqlx-core/src/postgres/connection/stream.rs:25:1
    |
 25 | pub struct PgStream {
    | ------------------- method `write` not found for this struct
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `AsyncWriteExt` which provides `write` is implemented but not in scope; perhaps you want to import it
    |
  1 + use sqlx_rt_oldapi::AsyncWriteExt;
    |
help: there is a method `write_i8` with a similar name
    |
183 |                 self.stream.write_i8(Close::Statement(id));
    |                                  +++

error[E0308]: mismatched types
   --> sqlx-core/src/postgres/copy.rs:307:31
    |
307 |               conn.stream.write(CopyFail::new(
    |  _________________________-----_^
    | |                         |
    | |                         arguments to this method are incorrect
308 | |                 "PgCopyIn dropped without calling finish() or fail()",
309 | |             ));
    | |_____________^ expected `&[u8]`, found `CopyFail`
    |
note: method defined here
   --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/io/util/async_write_ext.rs:124:12
    |
124 |         fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self>
    |            ^^^^^

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `sqlx-core-oldapi` (lib) due to 12 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `sqlx-core-oldapi` (lib) due to 12 previous errors
Process completed with exit code 101.

@cursor
Copy link

cursor bot commented Sep 16, 2025

I implemented a new write method on BufStream and PgStream to streamline message serialization, making it easier to send data over the connection. This refactoring simplifies the API for writing messages to the underlying buffer.

  • I added a pub fn write<'en, T>(&mut self, value: T) method to BufStream in sqlx-core/src/io/buf_stream.rs, which internally calls write_with using a default context.
  • I introduced #[inline] pub(crate) fn write<'en, T>(&mut self, message: T) and #[inline] pub(crate) fn flush(&mut self) methods to PgStream in sqlx-core/src/postgres/connection/stream.rs. These methods delegate directly to the underlying BufStream's new write and existing flush methods, providing a more direct interface for sending Postgres messages.
  • I updated the Drop implementation for PgCopyIn in sqlx-core/src/postgres/copy.rs to correctly reference message::CopyFail when calling the new conn.stream.write method, ensuring proper namespace resolution.

Open in Cursor Open in Web

Learn more about Cursor Agents

@lovasoa
Copy link
Collaborator Author

lovasoa commented Sep 16, 2025

@cursoragent

Checking sqlx-core-oldapi v0.6.48 (/home/runner/work/sqlx-oldapi/sqlx-oldapi/sqlx-core)

error[E0433]: failed to resolve: use of unresolved module or unlinked crate message
--> sqlx-core/src/postgres/copy.rs:307:31
|
307 | conn.stream.write(message::CopyFail::new(
| ^^^^^^^ use of unresolved module or unlinked crate message
|
help: to make use of source file sqlx-core/src/postgres/message/mod.rs, use mod message in this file to declare the module
--> sqlx-core/src/lib.rs:25:1
|
25 + mod message;
|
help: consider importing this struct through its public re-export
|
1 + use crate::postgres::message::CopyFail;
|
help: if you import CopyFail, refer to it directly
|
307 - conn.stream.write(message::CopyFail::new(
307 + conn.stream.write(CopyFail::new(
|

For more information about this error, try rustc --explain E0433.
error: could not compile sqlx-core-oldapi (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile sqlx-core-oldapi (lib) due to 1 previous error
Process completed with exit code 101.

@cursor
Copy link

cursor bot commented Sep 16, 2025

I performed a minor refactoring to improve code clarity and consistency within the PostgreSQL copy-in functionality. This change simplifies a constructor call in the Drop implementation for PgCopyIn.

  • Modified sqlx-core/src/postgres/copy.rs to use the unqualified CopyFail::new constructor instead of message::CopyFail::new within the Drop implementation for PgCopyIn. This change simplifies the call site, likely due to an updated use statement or module structure.

Open in Cursor Open in Web

Learn more about Cursor Agents

@lovasoa lovasoa closed this Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants