fix(backend): resolve clippy lints#101
Conversation
Addresses 6 of the 8 clippy findings surfaced by the new rust CI job: - needless_return (server.rs) - match_like_matches_macro (server.rs) - ptr_arg: &Vec<T> -> &[T] (event_filter.rs) - needless_borrow (event_filter.rs) - manual_is_multiple_of (event_listener.rs) - clone_on_copy (serializable_event.rs) Remaining (require manual judgment, deferred): large_enum_variant (server.rs), should_implement_trait for from_str (event_listener.rs).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR resolves all 8 Clippy warnings surfaced by the new
Confidence Score: 5/5All changes are mechanical Clippy lint fixes with no behavioral change; safe to merge once the stacking dependency on #100 lands. Every fix is a direct, correct application of what Clippy prescribes — boxing the large enum variant, removing redundant borrows/casts/clones, using idiomatic No files require special attention; the
|
| Filename | Overview |
|---|---|
| backend/src/lib/server.rs | Boxes the large EventData variant, removes redundant return, and replaces if-let chain with matches! — all correct and no behavioral change. |
| backend/src/lib/event_listener.rs | Renames from_str → from_name (single call site updated) and replaces % 100 == 0 with .is_multiple_of(100); both are correct mechanical changes. |
| backend/src/lib/event_filter.rs | Replaces &Vec<T> with &[T] in ArrayPrefixFilter::matches and removes the redundant borrow in the is_native_transfer call; both are idiomatic improvements with no semantic change. |
| backend/src/lib/serializable_event.rs | Drops .clone() on the u64 field timestamp_ns — trivially correct since u64 is Copy. |
| backend/src/bin/client.rs | Removes redundant as u64 casts from u64 - u64 subtractions; safe since both operands and Duration::from_nanos already operate on u64, but this change is not described in the PR. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ExecEventRing / Snapshot] -->|event descriptor| B[event_to_data]
B -->|EventName::from_name| C{known event?}
C -->|None| D[skip event]
C -->|Some EventData| E[run_event_forwarder_task]
E -->|Box::new event_data| F[broadcast::Sender EventDataOrMetrics]
F -->|EventDataOrMetrics::Event Box EventData| G[process_event]
G -->|&*event_data| H[SerializableEventData::from]
H --> I{filter.matches_event?}
I -->|yes| J[events_buf push]
I -->|no| K[discard]
J --> L[client_write_task send over WebSocket]
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
backend/src/bin/client.rs:113-123
**Undocumented change not listed in PR description**
Two `as u64` casts are removed here (`event.timestamp_ns - txn_start_ns` and `event.timestamp_ns - client_state.block_start_ns`). Both operands are already `u64`, so the cast was a no-op and the removal is correct, but neither change appears in the PR's list of 8 lint fixes. Looks like a `clippy::unnecessary_cast` fix that slipped in — worth noting for completeness.
Reviews (4): Last reviewed commit: "fix(backend): remove redundant u64 casts..." | Re-trigger Greptile
| event_count += 1; | ||
|
|
||
| if event_count % 100 == 0 { | ||
| if event_count.is_multiple_of(100) { |
There was a problem hiding this comment.
is_multiple_of requires Rust ≥ 1.87.0
<uN>::is_multiple_of was stabilized in Rust 1.87.0 (May 2025). The CI container pins rust:1.91-slim so the build will pass, but Cargo.toml has no rust-version field. Any contributor running cargo build or cargo clippy locally with a stable toolchain older than 1.87 will hit a compile error with no obvious hint about the minimum required version. Adding rust-version = "1.87" to Cargo.toml lets cargo surface a clear diagnostic instead of a confusing "method not found" error.
Prompt To Fix With AI
This is a comment left during a code review.
Path: backend/src/lib/event_listener.rs
Line: 287
Comment:
**`is_multiple_of` requires Rust ≥ 1.87.0**
`<uN>::is_multiple_of` was stabilized in Rust 1.87.0 (May 2025). The CI container pins `rust:1.91-slim` so the build will pass, but `Cargo.toml` has no `rust-version` field. Any contributor running `cargo build` or `cargo clippy` locally with a stable toolchain older than 1.87 will hit a compile error with no obvious hint about the minimum required version. Adding `rust-version = "1.87"` to `Cargo.toml` lets `cargo` surface a clear diagnostic instead of a confusing "method not found" error.
How can I resolve this? If you propose a fix, please make it concise.- large_enum_variant: box the 640-byte Event variant of EventDataOrMetrics (Event(Box<EventData>)). Since From::from infers its parameter type from the argument (deref coercion does not apply), the match-site call passes &*event_data to select From<&EventData>; construction uses Box::new(..). - should_implement_trait: rename inherent EventName::from_str -> from_name (and its single caller) so it no longer shadows std::str::FromStr::from_str.
Surfaced once the lib compiled clean: timestamp_ns is u64, so the (u64 - u64) as u64 casts are redundant; drop the cast and parens.
9e056d8 to
de4daf8
Compare
Resolves all 8 clippy findings surfaced by the new
rustCI job (#100) socargo clippy -D warningspasses.Mechanical fixes (equivalents of
cargo clippy --fix)server.rsneedless_returnreturnserver.rsmatch_like_matches_macromatches!event_filter.rsptr_arg&Vec<T>→&[T]event_filter.rsneedless_borrow&event_listener.rsmanual_is_multiple_of.is_multiple_of(100)serializable_event.rsclone_on_copy.clone()onu64Manual fixes (not auto-fixable)
server.rslarge_enum_variantEventDataOrMetrics::Event(Box<EventData>); thefrom(&event_data)call site deref-coerces, construction now usesBox::new(..)event_listener.rsshould_implement_traitEventName::from_str→from_name(+ its single caller) so it no longer shadowsstd::str::FromStr::from_strNo behavioral change. With these, the
rustjob (fmt+clippy -D warnings+build) should be fully green.