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
Leak: dropping a Box of a recursive enum frees the box but not the Box inside the enum (Box.new(L.Cons(5, Box.new(L.Nil)))) #1456
Spec: §2 ownership (a value is released by its owner's scope; the mission's "leaking is a defect"). Route: debug allocator.
Dropping a Box of a recursive enum frees the outer box but not the box inside it:
use std.box.Box
enum L:
Cons(v: i64, next: Box[L])
Nil
fn main:
let b = Box.new(L.Cons(5, Box.new(L.Nil)))
print("made")
$ with run --debug-alloc leak5.w
made
debug-alloc: LEAK addr=… size=32 origin=with_alloc
debug-alloc: leak count=1
The same leak when an owned list is matched and its Box payload is bound by value (match l: L.Cons(v, next) => v over L.Cons(4, Box.new(L.Cons(5, Box.new(L.Nil))))), or moved into a fn take(b: Box[L]). No leak for L.Cons(4, Box.new(L.Nil)) (one level), or when the payload pattern is _ (the enum's own drop glue recurses correctly). So a Box[L] dropped as a Box does not run the boxed L's drop glue.
Expected: leak count=0.
Reproduces on a stage1 of origin/main 1c76062 and on the #1443 branch. Found while writing the #1443 matrix (owned-subject control case).
Activity
MIR: a generic receiver reached through a reference is borrowed at th…
MIR: a generic receiver reached through a reference is borrowed at th…
Codegen: a Box dropped as a Box drops its pointee by type — Box[L] of…
Codegen: a Box dropped as a Box drops its pointee by type — Box[L] of…
Codegen: a Box dropped as a Box drops its pointee by type — Box[L] of…
Codegen: a Box dropped as a Box drops its pointee by type — Box[L] of…
Codegen: a Box dropped as a Box drops its pointee by type — Box[L] of…
ehartford commentedon Sep 26, 2026
Verified fixed on main 55739d4: a Box of a recursive enum frees the inner Box (--debug-alloc leak count=0).