You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spec-vs-implementation contradiction found during #677.
docs/completed/mutability.md (canonical, Eric-authored): "Function parameters are implicitly rebindable inside the function body. There is no mut x: T parameter modifier." — with the worked example fn f(x: i32): x = x + 1 // OK, and a whole "Parameter Rebinding" section defining local-rebind-contributes-no-effect semantics.
Implementation: parameters are bound with mut=0 (SemaCheck.check_fn_body_with_sig_at param loop), so x = x + 1 on any parameter is rejected with cannot assign to immutable variable.
Repro:
fn f(x: i32) -> i32:
x = x + 1
x
→ error: cannot assign to immutable variable.
Per the doc the fix is binding params mut=1 and keeping the effect-summary rule that the rebinding operation itself contributes nothing (the RHS still contributes normally). Interaction to watch: D12's scalar let-receiver guard treats immutable bindings as non-mutatable receivers — once params become rebindable, x.bump() on a by-value scalar param becomes legal callee-local mutation (consistent with mutability.md's model). Also note non-Copy share-place params: mutability.md says their rebinding is a LOCAL rebind (caller unaffected) — distinct from bare-self writes in mut fn, which are place writes (D12); the two must not be conflated in MIR lowering.
Not wired into #677 to keep that change scalar-scoped; needs its own cycle with effect/borrow fixtures.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): needs a ruling. Parameter rebinding is refused:
fn f(x: i32) -> i32:
x = x + 1
x
error: cannot assign to immutable variable
The only text that says parameters are rebindable is mutability.md, now under docs/completed/ (history, not doctrine), and the comment of test/compile_errors/err_mut_nonself_param.w. The current spec does not state it either way: §9 and §29 say nothing about assigning to a parameter. The question: are parameters immutable bindings (today's behavior, which the spec would then state), or implicitly rebindable as the old document said (the compiler would change; an owned parameter rebound is a local rebind with no effect)? D5/D110 settle the mode of a parameter, not its rebindability.
Ruled, 2026-11-18 (D220): parameters are immutable bindings, with an error that names both fixes. var x = x should already work: §29.8's consuming-rebind exception covers it, and refusing it for a parameter is an inconsistency to fix.
Activity
Sema: mut fn on scalar owners lowers via share-place (D12, #677)
Docs: handoff — D12 scalar tier implemented (566bc58); #689/#690 file…
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): needs a ruling. Parameter rebinding is refused:The only text that says parameters are rebindable is
mutability.md, now underdocs/completed/(history, not doctrine), and the comment oftest/compile_errors/err_mut_nonself_param.w. The current spec does not state it either way: §9 and §29 say nothing about assigning to a parameter. The question: are parameters immutable bindings (today's behavior, which the spec would then state), or implicitly rebindable as the old document said (the compiler would change; an owned parameter rebound is a local rebind with no effect)? D5/D110 settle the mode of a parameter, not its rebindability.ehartford commentedon Nov 19, 2026
Ruled, 2026-11-18 (D220): parameters are immutable bindings, with an error that names both fixes.
var x = xshould already work: §29.8's consuming-rebind exception covers it, and refusing it for a parameter is an inconsistency to fix.D218, D219 and D220 recorded: Eric's rulings of 2026-11-18 on #615, #919
A parameter is an immutable binding, and the consuming rebind applies…