refactor(payload): mark fallible-context infallibles as unreachable!()#1885
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
Five `.expect()` sites in `lading_payload` live inside `Result`-returning functions but are themselves guarded by local invariants that make their `Err` branch unreachable. The agent inventory initially classified them as "Cat-1: `?`-propagation feasible" because the surrounding function returns `Result`, but propagating with `?` would introduce dead error paths — the parse cannot fail when `start_is_num` is true, and the chars-iter cannot return `None` when `start_is_char` (which requires `start.len() == 1`) is true. Sites: - `common/strings/string_list_pool.rs:179,182` (parse::<u32>() guarded by `start_is_num`/`end_is_num` flags set just above) - `common/strings/string_list_pool.rs:192,196` (chars().next() on strings guaranteed non-empty by `start_is_char`/`end_is_char`) - `templated_json/resolver.rs:155` (raw_defs[idx].take() inside the three-color (white/grey/black) visit state machine; reachable only when `black[idx] == false && grey[idx] == false`, which corresponds to raw_defs[idx] being Some) Same pattern as the prior `unreachable!()` refactor (PR #1884). No runtime behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
e1fe7c8 to
1912643
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 5
.expect()sites inlading_payloadto.unwrap_or_else(... unreachable!("...")). The sites all live insideResult-returning functions but are themselves guarded by local invariants — propagating with?would introduce dead error paths.Sites
common/strings/string_list_pool.rs:179start.parse::<u32>().expect(...)start_is_numwas set tostart.parse::<u32>().is_ok()27 lines abovecommon/strings/string_list_pool.rs:182end.parse::<u32>().expect(...)endcommon/strings/string_list_pool.rs:192start.chars().next().expect(...)start_is_char = start.len() == 1 && !start_is_numcommon/strings/string_list_pool.rs:196end.chars().next().expect(...)endtemplated_json/resolver.rs:155self.raw_defs[idx].take().expect(...)!black[idx] && !grey[idx], which corresponds toraw_defs[idx]beingSomeWhy
unreachable!()and not?An earlier draft of this PR used
?-propagation (the agent's initial recommendation, since the containing functions returnResult). On review the choice changes: these aren't real error paths — the parses cannot fail becausestart_is_numwas set from a successfulparse::<u32>().is_ok(), andchars().next()cannot returnNoneon a string the local code has just established haslen() == 1.unreachable!()documents that fact;?would leave a deadErr(Error::MalformedPattern{...})branch behind that's never produced.These sites fit the same shape as the previous
unwrap_or_else(|| unreachable!())refactor (#1884), but were initially split out because they live inResult-returning functions. They're being landed in their own PR for review clarity, not because they need a different treatment.Motivation
Third per-crate cleanup-PR in the stack started by #1882. Future PRs in this sub-stack:
block.rs,random_string_pool.rs,string_list_pool.rswhere the invariant is established in the same function (same pattern as this PR; separated by the "originally in aResultfn" distinction)..expect()is the contract (handle-table lookups, documented API panics) — annotated with#[expect(clippy::expect_used, reason = "...")].block.rs:123(thearbitrary::Arbitraryimpl forBlockcan panic onu32::arbitraryreturning 0).lading_payloadquarantine.Related issues
Stacked on #1884.
Additional Notes
cargo build --all-targets --all-features✓cargo clippy --all-targets --all-features✓cargo test -p lading-payload --lib✓ (244 passed)