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
A Drop value bound in a block statement or if arm is destroyed at function exit, not at the end of its scope #1532
Found while writing a D60 fixture. Reproduced on origin/main 5848ae9 (stage1):
type Tracer { id: str }
impl Drop for Tracer:
fn drop(move self: Self): print(f"drop {self.id}")
fn main:
{
let t = Tracer { id: "a".clone() }
}
print("after block")
if true:
let u = Tracer { id: "b".clone() }
print("after if")
prints
after block
after if
drop b
drop a
Expected drop a before after block and drop b before after if: §11.7's syntax-trait table (Drop — destructor — automatic at scope exit) and §21.1 rule 7 ("The compiler inserts implicit drop points at scope exit in reverse declaration order"); the mission: "a resource lives in its scope and is released when the scope ends". A binding declared in a braced block statement or an if arm is destroyed at the function's exit instead. (A helper function's local drops at that function's end as expected.)
Verified fixed on main 55739d4: a Drop value bound in an if arm is destroyed at the end of the arm (in block, drop 1, after block; --debug-alloc leak count=0).
Activity
ehartford commentedon Sep 26, 2026
Verified fixed on main 55739d4: a Drop value bound in an
ifarm is destroyed at the end of the arm (in block,drop 1,after block; --debug-alloc leak count=0).