Pay the clippy debt in walgit-proto - #23
Open
ethanstoner wants to merge 1 commit into
Open
Conversation
5ccc405 turned on the strict gate and left the existing debt to follow-up commits. This is walgit-proto's share: 27 of the workspace's 74 errors, after which the crate is clean under `-D warnings`. Nineteen were `doc_markdown` inside `mod v1`, where prost reproduces the doc comments written in wal.proto — the lint is judging the schema's prose, not ours, so the module carries a targeted allow. The rest are hand-written: - `frame::encode_entry` expects on `encode`, which fails only when the buffer lacks capacity — and `reserve(encoded_len())` runs immediately above. The invariant is now stated in an allow rather than implied. - `frame::decode_entries` indexed and sliced a buffer read from the bucket, and narrowed a `u64` frame length to `usize` with `as`. The bounds were in fact all established — `pos` never exceeds `buf.len()` and the length was checked against `remaining()` first — so this is a rewrite in checked operators, not a fix: `get(pos..)`, `usize::try_from` and `get(..len)`, each falling out of the loop the way a short read already did. A test pins that contract so the rewrite is provably behaviour-preserving; it passes against the old body too, by design. - `time::from_system` / `to_system` used `as` across the signed boundary. `cast_signed`/`cast_unsigned` say the same thing and are checked by the reader instead of the compiler; `to_system` clamps to zero first, so neither cast can change the value it carries. walgit-proto is clippy-clean, `cargo fmt --check` is clean, its four tests pass, and walgit-wal, walgit-store and walgit-bundle are unchanged-green.
This was referenced Aug 27, 2026
|
Ran this here on rust 1.97.1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #15, which says the gate is red "until the existing debt is paid ... fixing is left to follow-up commits." This pays
walgit-proto's share — 27 of the workspace's 74 errors — after which the crate is clean under-D warnings.Deliberately one crate. The rest of the debt (
walgit-confighas 45, pluswalgit-server/build.rs) is untouched here so each slice stays reviewable, and so this does not collide with #17, #19 or #20.What is in it
19 ×
doc_markdowninsidemod v1. prost reproduces the doc comments written inwal.proto, so the lint is judging the schema's prose rather than ours. Targeted allow on the module.frame::encode_entry—expectonencode, which fails only on insufficient capacity, andreserve(encoded_len())runs immediately above.Cargo.toml's own note says known-infallible cases should "say so with a targeted#[allow]or anexpect()naming the invariant"; this now does both.frame::decode_entries— indexed and sliced a buffer read from the bucket and narrowed au64frame length withas. Rewritten in checked operators:get(pos..),usize::try_from,get(..len), each falling out of the loop exactly where a short read already did.time::from_system/to_system—asacross the signed boundary becomescast_signed/cast_unsigned.to_systemclamps to zero first, so neither cast can change the value it carries.On the parser rewrite — not a bug fix
I want to be exact about this, because "checked operators" invites the reading that something was broken. Nothing was.
The bounds were already established:
pos = buf.len() - probe.len() + lenafter aremaining() >= lencheck cannot exceedbuf.len(), and&probe[..len]was guarded by that same check. Even theu64 → usizenarrowing was harmless, since a truncated length still failed theremaining()test on both 32- and 64-bit. These were theoretical panic paths that the lint flags and the code never took.So the added test passes against the old body as well, by construction. It is not there to catch a regression that existed; it is there so the rewrite is provably behaviour-preserving, which is the only claim I can make honestly. If you would rather this PR not carry a test that cannot fail against
main, say so and I will drop it.Verification
cargo clippy -p walgit-proto --all-targets -- -D warningsmain→ 47cargo fmt --check -p walgit-protocargo test -p walgit-protocargo test -p walgit-wal -p walgit-store -p walgit-bundlejust clippystill fails overall, as expected — the remaining 47 live in the crates this PR does not touch. Happy to take those in the same shape if this one lands the way you want it.