Repository navigation
Description
Remove Result from the hardcoded @[must_use] set
Summary
Spec v7.0+ removed Result from the @[must_use] exhaustiveness rule: discarding or partially matching a Result carries no obligation (§10.1). The compiler still hardcodes Result (alongside Task) as must_use, so statement-position partial matches on Result are rejected and users are forced into _ => {} ceremony — exactly the ritual §10.1 and AGENTS.md forbid ("a dropped Result does nothing, so a must-use Result diagnostic is forbidden"). This removes the hardcoding; Task and user @[must_use] types keep the rule.
Spec
§10.1 Result and Option: "Discarding a Result or Option has no side effect. The compiler does not require ceremony such as let _ = expr merely to acknowledge that discard." §9.7 Pattern Matching (exhaustiveness): statement-position match allows partial matches; only must-use types require exhaustiveness there — and Result is no longer one of them. Expected-legal example:
match db.execute("..."):
Ok(n) => log(n)
// legal: unmatched Err arms are a no-op (§10.1)
Current state
src/SemaDecl.w:116-122: after decl collection,// Hardcode Result and Task as must_use typesinserts bothResultandTasksymbols intomust_use_types.src/SemaCheck.w:6070-6081(check_matchexhaustiveness gate): statement-position matches normally allow partial coverage, butmust_use_types.contains(type_sym)forcesrequire_exhaustive = 1(comment at 6077-6078), producing "non-exhaustive match: missing variant" for Ok-only Result matches.test/behavior/must_use_match.wcurrently asserts the old behavior, including a section commented "Result (hardcoded must_use) requires exhaustive match".- User
@[must_use]attribute types andTaskflow into the samemust_use_typesset and must keep working (a droppedTaskcancels it — its discard matters, so its rule is legitimate). - Statement-position discard of a Result (
db.execute(...)as an expression statement) already compiles without ceremony (campaign 10.1.1.3-5, verified manually) — this issue is only about the partial-match leg.
Implementation plan
src/SemaDecl.w:116-122: delete thesym_resultlookup/insertion; keepsym_task. (The comment becomes "Hardcode Task as must_use".)test/behavior/must_use_match.w: replace the Result section with the inverse expectation — a statement-positionmatchon aResultcovering onlyOkmust compile and run; keep the@[must_use] enum Statusexhaustiveness sections and the wildcard-satisfies case unchanged.- Grep the test suite and stdlib for
_ => {}/_ =>arms that exist only to satisfy the old Result rule and simplify where they obscure a test's point (grep -rn "_ =>" test/ | grep -i result); keep this cleanup minimal and in the same commit only when the file is already being touched — do not batch unrelated edits. - Confirm there is no second enforcement site:
grep -n must_use_types src/(expected: the SemaDecl insert, the attribute-collection insert for user types, and the SemaCheck gate at 6079). - Sema-only change; no rt/Link/seed hazard. Standard gates.
Edge cases that must keep failing/working:
- Expression-position match on Result still requires exhaustiveness (it produces a value).
@[must_use]user enums still require exhaustive statement matches; wildcard still counts as catch-all.Taskstatement-position handling unchanged (§14.7 disposition rules are separate machinery).
Test plan
test/behavior/behav_result_partial_match.w(expect-stdoutok):(second match's Err is silently skipped — the §10.1 no-op guarantee).fn fallible(n: i32) -> Result[i32, str]: if n > 0: Ok(n) else: Err("neg") fn main: match fallible(1): Ok(v) => assert(v == 1) match fallible(-1): Ok(_) => assert(false, "unreachable") print("ok")- Update
test/behavior/must_use_match.wper step 2 (Result partial match compiles;@[must_use]Status still enforced — keep its existing negative coverage or pair it with atest/compile_errors/case asserting "non-exhaustive match" for the user must-use type). test/compile_errors/match_expr_position_result.w: expression-positionlet x = match r: Ok(v) => v(no Err arm) →//! expect-error: non-exhaustive.- Overlap: discard-statement coverage lives in Tests: result discard coverage (§10) #521; do not duplicate here.
Acceptance criteria
- Statement-position partial match on
Resultcompiles with no diagnostic and unmatched variants are a no-op at runtime - Expression-position Result matches still require exhaustiveness
-
Taskand user@[must_use]types still require exhaustive statement-position matches -
test/behavior/must_use_match.wupdated to the new contract - with build && with build :fixpoint && with build :test pass
Dependencies
- Blocks Tests: result discard coverage (§10) #521 (result-discard test coverage asserts the no-ceremony contract this issue completes). No other dependencies.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 10.1.1.4 (no-ceremony rule; see also #521 for 10.1.1.3-5 test coverage). Spec reference: §9.7 Pattern Matching (exhaustiveness), §10.1 Result and Option — spec v7.0.
Activity
Spec v7.0/v7.1: resolve contradictions, integrate rulings, collection…
ehartford commentedon Jun 11, 2026
Implemented in 10e871a. Result is no longer hardcoded as must-use; partial statement-position Result matches are legal no-ops, while user @[must_use] types and Task still require exhaustive statement-position matches. Expression-position Result matches still check generic enum exhaustiveness, and for-comprehensions now diagnose mixed Option/Result carrier chains directly. Verification passed: build, fixpoint, full test suite, and test-green.