refactor(payload): mark in-function invariants as unreachable!()#1890
Draft
goxberry wants to merge 1 commit into
Draft
Conversation
Contributor
Author
This was referenced May 22, 2026
This comment has been minimized.
This comment has been minimized.
This was referenced May 22, 2026
Six `usize → u32` and `Option<char>` `.expect()` sites in `lading_payload` are guarded by invariants established earlier in the same function (or at pool construction): - `block.rs:752` — `bytes.len().try_into()` to u32 inside `construct_block`; `bytes` is sized by `chunk_size: u32`. - `random_string_pool.rs:125,127` — `lower_idx.try_into()` and `bytes.try_into()` for `Handle::PosAndLength(u32, u32)`. The pool's inner length is asserted to fit in u32 at construction (`with_size` line 35); `lower_idx` and `bytes` are both bounded by it. - `string_list_pool.rs:253,260` — `u32::try_from(idx)` inside `range_value_at`; `idx` is bounded by the range length, which fits in u32 by construction. - `string_list_pool.rs:256` — `char::from_u32(*start as u32 + offset)` inside the same function; `*start..=*end` is a valid Unicode scalar range by parser invariant. Same pattern as #1884 and #1885. No runtime behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
e1fe7c8 to
1912643
Compare
8215c40 to
1d0c347
Compare
This was referenced May 22, 2026
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.

What does this PR do?
Converts 6
.expect()sites inlading_payloadto.unwrap_or_else(... unreachable!("...")). Each site is guarded by an invariant established earlier in the same function or at type/pool construction.Sites
block.rs:752bytes.len().try_into()→ u32 inconstruct_blockbytesis sized bychunk_size: u32;bytes.len() <= chunk_sizecommon/strings/random_string_pool.rs:125lower_idx.try_into()→ u32lower_idx < self.inner.len(); pool length asserted ≤ u32::MAX atwith_sizeline 35common/strings/random_string_pool.rs:127bytes.try_into()→ u32bytes < self.inner.len(); same assertcommon/strings/string_list_pool.rs:253u32::try_from(idx)inrange_value_atidxbounded by range length, which fits in u32 by parser constructioncommon/strings/string_list_pool.rs:256char::from_u32(*start as u32 + offset)*start..=*endis a parser-validated Unicode scalar rangecommon/strings/string_list_pool.rs:260u32::try_from(idx)(Numbervariant)Why this PR is separate from #1885
Both PRs convert
.expect()tounwrap_or_else(... unreachable!()). The split is by where the invariant lives: #1885 (Group A) handles five sites insideResult-returning functions where the agent initially recommended?-propagation; this PR (Group B) handles six sites where the surrounding function does not returnResult, so the only options were.expect()orunreachable!(). The treatment ends up identical, but reviewing them in one batch made the inventory harder to follow.Motivation
Fourth per-crate cleanup PR in the stack started by #1882. Remaining sub-stack:
.expect()sites where the message is the contract (handle-table lookups, documented API panics) — annotated with#[expect(clippy::expect_used, reason = "...")].block.rs:123(thearbitrary::Arbitraryimpl forBlockcan panic whenu32::arbitraryreturns 0).lading_payloadquarantine.Related issues
Stacked on #1885.
Additional Notes
cargo build --all-targets --all-features✓cargo clippy --all-targets --all-features✓cargo test -p lading-payload --lib✓ (244 passed)