Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
- Replaced 5 additional infallible-by-construction `.expect()` sites in
`lading_payload` with `.unwrap_or_else(|_| unreachable!("..."))` /
`.unwrap_or_else(|| unreachable!("..."))`. Covered: 4 sites in
`string_list_pool::validate_range` (parse-and-chars-iter calls guarded by
flags set immediately above) and 1 site in
`templated_json::resolver::resolve_def` (take-from-`Option`-Vec inside a
three-color visit state machine). No runtime behavior change.
- Replaced 26 infallible-by-construction `.expect()` sites in `lading_payload`
with `.unwrap_or_else(|| unreachable!("..."))`, making the impossibility
structural and explicit. Sites covered: 20 `CONST_ARR.choose(rng)` against
Expand Down
16 changes: 8 additions & 8 deletions lading_payload/src/common/strings/string_list_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ impl StringListPool {

// Validate that ranges are not backwards
if start_is_num && end_is_num {
let start_num = start
.parse::<u32>()
.expect("start_is_num guarantees this parses");
let end_num = end
.parse::<u32>()
.expect("end_is_num guarantees this parses");
let start_num = start.parse::<u32>().unwrap_or_else(|_| {
unreachable!("start_is_num was set from start.parse::<u32>().is_ok()")
});
let end_num = end.parse::<u32>().unwrap_or_else(|_| {
unreachable!("end_is_num was set from end.parse::<u32>().is_ok()")
});
if start_num > end_num {
return Err(Error::MalformedPattern {
pattern: format!("{{{{{start}-{end}}}}}"),
Expand All @@ -189,11 +189,11 @@ impl StringListPool {
let start_char = start
.chars()
.next()
.expect("start_is_char guarantees non-empty");
.unwrap_or_else(|| unreachable!("start_is_char requires start.len() == 1"));
let end_char = end
.chars()
.next()
.expect("end_is_char guarantees non-empty");
.unwrap_or_else(|| unreachable!("end_is_char requires end.len() == 1"));
if start_char > end_char {
return Err(Error::MalformedPattern {
pattern: format!("{{{{{start}-{end}}}}}"),
Expand Down
2 changes: 1 addition & 1 deletion lading_payload/src/templated_json/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl Resolver {
self.grey[idx] = true;
let vgen = self.raw_defs[idx]
.take()
.expect("raw definition should exist");
.unwrap_or_else(|| unreachable!("raw_defs[idx] is Some when grey[idx] is first set"));
let resolved = vgen.resolve(self)?;
self.resolved_defs[idx] = Some(resolved);
self.grey[idx] = false;
Expand Down
Loading