Skip to content

fix(core): parse a hex id without chunks_exact, which clippy now rejects - #78

Merged
youhide merged 1 commit into
mainfrom
clippy-as-chunks
Aug 21, 2026
Merged

fix(core): parse a hex id without chunks_exact, which clippy now rejects#78
youhide merged 1 commit into
mainfrom
clippy-as-chunks

Conversation

@youhide

@youhide youhide commented Aug 21, 2026

Copy link
Copy Markdown
Owner

CI on main is red on all three platforms and this unblocks it. Not a plan item — a prerequisite for the one in #77.

What happened

Nothing about the code changed its mind; the lint did. A newer clippy on the CI runners raises clippy::chunks_exact_to_as_chunks for chunks_exact(2) over a constant. Clippy warnings are errors in this workspace, so hidegit-core stopped compiling under cargo clippy everywhere.

It is invisible locally: this machine has clippy 0.1.97, the runners have newer.

Why not the lint's own suggestion

as_chunks stabilised in exactly the version this workspace declares as its floor — 1.88, which rust-toolchain.toml and the MSRV job both pin. Putting a parser of untrusted repository input on the precise edge of the declared minimum is closer than it needs to be, and the MSRV job runs cargo check, not clippy, so it would not have been the thing to catch a mistake there.

Indexing is simpler and older than both spellings:

for i in 0..hex.len() / 2 {
    let pair = hex.get(i * 2..i * 2 + 2)?;
    buf[i] = u8::from_str_radix(pair, 16).ok()?;
}

str::get on a byte range yields None for anything that is not a character boundary, so a multi-byte character is rejected before it reaches the radix parser rather than after — which is exactly what the std::str::from_utf8 call it replaces was there to do. One fewer step, same refusals.

Behaviour

Unchanged. The three existing ObjectId tests cover the round trip, the SHA-256 length, and the malformed input that must be refused — all still pass, and no test needed touching, which is the point.

Gate

cargo fmt --all -- --check and cargo test -p hidegit-core green locally. The clippy half can only be verified by CI, since the lint does not exist in this machine's toolchain — that is the whole reason this PR exists.

…shape

Nothing about the code changed its mind; the lint did. A newer clippy on CI
raises `chunks_exact_to_as_chunks` for `chunks_exact(2)` over a constant, and
clippy warnings are errors here, so `main` stopped building on all three
platforms.

Two spellings were rejected before this one. `as_chunks` is the lint's own
suggestion, but it stabilised in exactly the version this workspace declares as
its floor, which is closer to the edge than a parser of untrusted input needs to
be. Indexing a range instead trades that lint for `needless_range_loop`.

So the digits are read directly. That removes the UTF-8 question rather than
answering it: any byte of a multi-byte character is above 0x7f and is simply not
a hex digit, so it is refused without a boundary check, and the `from_utf8` step
this replaces is gone rather than reimplemented.

`from_str_radix` accepted upper and lower case, and hand-rolled digits do not
get that for free, so a test now pins it — Git writes lowercase, people paste
either, and ids still come back lowercase the way Git spells them.
@youhide
youhide merged commit 2588d22 into main Aug 21, 2026
7 checks passed
@youhide
youhide deleted the clippy-as-chunks branch August 21, 2026 01:04
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.

1 participant