must-use-result: a feature pack's Result compared with undefined or null isn't looked at #167

Merged
sionzee merged 1 commit from pack-result-compared into main 2026-11-24 14:08:59 +01:00
Owner

Found reviewing #158 before landing it. std's Result is T | Err<E>, so after #158 made getItem and key return Result<Option<string>, E>, code written the way the docs showed before (return getItem(localStorage, "draft") !== undefined;) still type-checks, and on a store the browser refuses the Err counts as "draft present". Nothing reported it: must-use-result only fired when the value was dropped, logged or turned into text.

What changes

  • kept::weak_use recognises a comparison with undefined, void 0 or null as "only compares it with undefined, which an Err isn't either".
  • It counts as not looking only for a feature pack's safe version: in place (new LibCall::weak_use, reported in the pack loop of project.rs) and kept in a local (kept_results passes the pack calls as compared to kept::collect_in, and local() keeps such keepings as candidates). A function's own Result<void, E> tested with r === undefined still counts as a test (kept_results fixture, "Looked at: tested"), as do std's unsafe(...) and parseJson.
  • Pack safe versions logged in place (console.log(getItem(localStorage, k))) are now reported like the user's own functions; a pack call kept in a local nothing looks at was reported twice (pack loop and calls loop) and now once.
  • Docs: docs/rules/must-use-result.md ("A Result kept in a local"), CHANGELOG (#158's entry and a Fixed entry).
  • Test: fixes.rs::a_pack_result_compared_with_undefined_is_not_looked_at (in place !==, null ==, kept, logged).

Also carries the merged tree's counts after #157–#161: work-ceilings.json, and misses.txt (#160 fixed far failure-contract namespace-import; #161's new lifetime fixtures add 13 missing-mut hoist-const and 2 no-param-mutation type-alias; the must-use-result paren text halves with the duplicate gone; one unbounded-spread paren text from the new tuples case). Reasons unchanged.

Checked locally on this exact tree

cargo nextest run --workspace 431/431, full rewrites (blessed, then compared), typecheck, test:std, test:soundness, test:vite, test:docs.

🤖 Generated with Claude Code

Found reviewing #158 before landing it. std's `Result` is `T | Err<E>`, so after #158 made `getItem` and `key` return `Result<Option<string>, E>`, code written the way the docs showed before (`return getItem(localStorage, "draft") !== undefined;`) still type-checks, and on a store the browser refuses the `Err` counts as "draft present". Nothing reported it: `must-use-result` only fired when the value was dropped, logged or turned into text. ## What changes - **`kept::weak_use`** recognises a comparison with `undefined`, `void 0` or `null` as "only compares it with `undefined`, which an `Err` isn't either". - It counts as not looking **only for a feature pack's safe version**: in place (new `LibCall::weak_use`, reported in the pack loop of `project.rs`) and kept in a local (`kept_results` passes the pack calls as `compared` to `kept::collect_in`, and `local()` keeps such keepings as candidates). A function's own `Result<void, E>` tested with `r === undefined` still counts as a test (`kept_results` fixture, "Looked at: tested"), as do std's `unsafe(...)` and `parseJson`. - Pack safe versions logged in place (`console.log(getItem(localStorage, k))`) are now reported like the user's own functions; a pack call kept in a local nothing looks at was reported twice (pack loop and calls loop) and now once. - Docs: `docs/rules/must-use-result.md` ("A Result kept in a local"), CHANGELOG (#158's entry and a Fixed entry). - Test: `fixes.rs::a_pack_result_compared_with_undefined_is_not_looked_at` (in place `!==`, `null ==`, kept, logged). Also carries the merged tree's counts after #157–#161: `work-ceilings.json`, and `misses.txt` (#160 fixed `far failure-contract namespace-import`; #161's new `lifetime` fixtures add 13 `missing-mut hoist-const` and 2 `no-param-mutation type-alias`; the must-use-result paren text halves with the duplicate gone; one `unbounded-spread` paren text from the new tuples case). Reasons unchanged. ## Checked locally on this exact tree `cargo nextest run --workspace` 431/431, full rewrites (blessed, then compared), typecheck, test:std, test:soundness, test:vite, test:docs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
must-use-result: a pack's Result compared with undefined or null isn't looked at
Some checks failed
Tests / test (pull_request) Has been cancelled
Benchmarks / bench (pull_request) Has been cancelled
27c5493ada
std's Result is T | Err<E>, so getItem(localStorage, k) !== undefined (as
the docs showed before #158) took the Err of a refused store for a stored
value, with no finding. Comparing a feature pack's safe version with
undefined or null, in place or kept in a local, is now a must-use-result;
a function's own Result<void, E> tested with r === undefined still counts as
looked at. Pack safe versions logged in place are reported too, and a kept
one is no longer reported twice.

Also the merged tree's counts after #157-#161: work ceilings, and
misses.txt (#160 fixed failure-contract namespace-import; #161's new
lifetime fixtures add 13 missing-mut hoist-const and 2 no-param-mutation
type-alias cases; reasons unchanged).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee deleted branch pack-result-compared 2026-11-24 14:08:59 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!167
No description provided.