Skip to content

chore: clippy#1011

Draft
levkk wants to merge 8 commits into
mainfrom
levkk-clippy-run
Draft

chore: clippy#1011
levkk wants to merge 8 commits into
mainfrom
levkk-clippy-run

Conversation

@levkk
Copy link
Copy Markdown
Collaborator

@levkk levkk commented May 27, 2026

  1. Clippy pass
  2. Refactor BackendKeyData secret into an enum and remove Copy

PoolUnhealthy,

#[error("checked in untracked connection: {0}")]
UntrackedConnCheckin(BackendKeyData),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine if we don't need it, but I really don't think it'd be a problem to do Box<BackendKeyData> either

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was probably to preserve the Copy derive on the Error struct.


let server = Box::new(Server::default());
let server_id = *server.id();
let server_id = server.id().clone();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all due to removing Copy from the BackendKeyData structs, right? I can't imagine clippy recommending this 😅

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clippy, this is a refactor. I removed Copy from BackendKeyData, yup. It's now an enum, with the most likely variant resulting in a copy of 4 bytes, and the unlikely one an alloc of up to 256 bytes (variable secret key size in Postgres protocol 3.2 which will probably not be adopted for another decade).

Comment on lines +317 to +321
let id = if let Some(key_data) = key_data {
key_data
} else {
BackendKeyData::new()
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let id = if let Some(key_data) = key_data {
key_data
} else {
BackendKeyData::new()
};
let id = key_data.unwrap_or_else(BackendKeyData::new)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually what clippy complained about and told me not to do. It also made an incorrect automatic edit (unwrap_or_default()).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait clippy complained about using unwrap_or_else? I would 100% expect it to complain about unwrap_or but not what I suggested. You could also do unwrap_or_else(|| BackendKeyData::new()) if passing the function pointer seems too clever but I would be shocked if clippy actually told you to write this instead of my suggestion

Copy link
Copy Markdown
Contributor

@sgrif sgrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that the semantic changes around BackendKeyData have been a separate PR, since doing that and clippy at the same time.

Given that we're keeping the same semantics as the code had before, this seems fine with one minor nit. However, I do think it'd be worth actually evaluating each of those clones to see if they really need to be passing owned data or not.

@levkk levkk marked this pull request as draft May 27, 2026 18:46
@blacksmith-sh
Copy link
Copy Markdown
Contributor

blacksmith-sh Bot commented May 27, 2026

Found 1 test failure on Blacksmith runners:

Failure

Test View Logs
prepared_spec/
prepared_statements = disabled fails named extended-protocol statements in transaction
pool mode
View Logs

Fix in Cursor

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