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
{{ message }}
Repository navigation
An assignment used as a value outside a tail duplicates its non-Copy value: double free / wrong value (§9.1, D60) #1479
Found implementing D60 (§9.1 tail assignments). D60 rules the value of an assignment in statement position (discarded) and as the tail of a body with a declared non-Unit return (a read of the place after the store, under the ordinary copy and move rules). An assignment used as a value anywhere else still lowers to its right-hand operand (MirLower.lower_expr, the NK_ASSIGN arm: "the expression value of lhs = rhs is rhs"), which the place has already taken. For a type that is not Copy that is a second owner.
Reproduced identically on origin/main 5848ae9 (stage1) and on the D60 branch, run --debug-alloc:
fn compute(s: &str): s.clone() ++ "!"
fn main:
var s = "".clone()
let t = (s = compute("x"))
print(t)
print(s)
prints x! twice, then debug-alloc: DOUBLE FREE ... origin=unknown.
let t = if p: s = compute("y") else: s = compute("n")
same double free (an arm of a non-tail value if; D43 keeps the arm's value).
var a = "".clone()
var b = "".clone()
a = b = compute("x")
print(a) // prints an empty line
print(b) // x!
wrong value, no allocator complaint: a receives the blanked operand.
i32 spellings are correct (a = b = 5 gives 5 and 5).
Expected: one owner. Under the D60 reading the value is a read of the place, so let t = (s = compute("x")) moves s out (a later print(s) is use-after-move), and a = b = compute("x") moves b into a. Whether that reading extends beyond the tail is a spec question (§9.1 now defines statement and tail positions only); until it is ruled, the compiler should at least not mint a second owner. The D60 PR adds the machinery this would reuse: Sema.tail_read_assigns / check_tail_read_place and MirBuilder.lower_assign(.., read_back) / read_assigned_place.
Ruled by Eric (D73, spec v7.5, PR #1784): an assignment expression's value is a read of the place after the store — C11 §6.5.16's rule under With's view semantics (a view; Copy copies, an owned demand on a non-Copy view is refused). D60's tail rule stands. Implementation on the batch-2 ownership layer.
Activity
Spec v7.5 (D72, D73): a Drop type whose all-zero storage is a live va…
ehartford commentedon Sep 27, 2026
Ruled by Eric (D73, spec v7.5, PR #1784): an assignment expression's value is a read of the place after the store — C11 §6.5.16's rule under With's view semantics (a view; Copy copies, an owned demand on a non-Copy view is refused). D60's tail rule stands. Implementation on the batch-2 ownership layer.
D73: an assignment in any value position yields a view of its place a…
Ownership: D72 liveness byte, D73 assignment-as-read, validator leak/…
Sema: an assignment an `unsafe:` or plain block yields as a body's ta…
Sema: an assignment an `unsafe:` or plain block yields as a body's ta…
Sema: an assignment an `unsafe:` or plain block yields as a body's ta…
Enums: payload discriminants, casts, generic layouts, and fn-type com…