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
Soundness: reassignment after move double-drops the moved-out Drop value #614
A reassignment of a var whose previous value was moved out still runs the
drop-before-overwrite on that (already moved) value — a double-drop / double-free
for a Drop type.
Repro
type R { id: i32, slot: *mut i32 }
impl Drop for R:
fn drop(move self: Self):
unsafe: *self.slot = *self.slot + 1
fn take(r: R): ()
fn make(slot: *mut i32) -> R: R { id: 1, slot }
fn main:
var drops = 0
var r = make(&raw mut drops)
take(r) // moves r1 into take; take drops r1 (drops=1)
r = make(&raw mut drops) // BUG: drop-before-overwrite drops r1 AGAIN (drops=2)
take(r) // drops r2 (drops=3)
print_i32(drops) // prints 3; correct is 2
print_i32(drops) prints 3; the correct count is 2. The reassignment r = make() drops r1 even though r1 was already consumed by take(r).
Root cause (direction)
MIR drop-before-overwrite for an assignment target does not consult whether the
target's current value was moved out; it emits the drop unconditionally. The
straight-line move ledger (M4) should mark r moved after take(r) so the
reassignment skips the drop (then re-marks it live with the new value).
Spec
§2.2 (after a move the source is invalid), §2.4 (drop on reassignment — drops the old value, but only if it is still owned). req 1.1.1.14 ("double-free … caught at
compile time. Always.").
Discovery
Surfaced while implementing loop conditional moves (#613): the §2.4 reinit-in-loop
pattern (while …: take(r); r = make()) over-counts drops by one per iteration.
The bug is independent of loops (straight-line repro above). Related to the
move-is-a-copy substrate #605/#606/#607.
Closing as fixed — reassignment after a move no longer double-drops: reset-on-move (spec §2.5.1) blanks the moved-out source, drop-before-overwrite on the blanked value is a no-op, and the reassigned value drops normally. Record: docs/completed/drop-elaboration-soundness.md; pinned by da_reassign_after_move (leak count=0, exact counts) and the loop-reinit fixtures. The static drop-elaboration approach this issue originally proposed was deliberately retired (§2.5.2).
Activity
Loops: sound conditional Drop moves (back-edge + break/continue dataf…
Generational ownership Stage 2/3: reset-on-move + guarded drop
docs: align drop/move ownership docs with the niche; archive complete…
Fix #617 thread races in the comptime parallel() compile path
ehartford commentedon Jul 2, 2026
Closing as fixed — reassignment after a move no longer double-drops: reset-on-move (spec §2.5.1) blanks the moved-out source, drop-before-overwrite on the blanked value is a no-op, and the reassigned value drops normally. Record: docs/completed/drop-elaboration-soundness.md; pinned by da_reassign_after_move (leak count=0, exact counts) and the loop-reinit fixtures. The static drop-elaboration approach this issue originally proposed was deliberately retired (§2.5.2).