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 &P field of a mut self receiver is moved and blanked when P: Drop — reading self.db into a child nulls the receiver's field (segfault) #1492
Spec: §2.2 / §2.5.1 (reset-on-move applies to moves of owned values), §3 (a &T is Copy). A &Db field read inside a mut fn of an ephemeral struct must be a copy; the field must keep its value.
Repro (seed 7c3ed983 / installed v0.15.2.1, and stage1 at ba2d5d1 — pre-existing):
type Db { n: i32, live: bool }
impl Drop for Db:
move fn drop():
if self.live: print(f"close db {self.n}")
type Stmt = ephemeral { parent: &Db, n: i32 }
impl Stmt:
fn step(): self.parent.n * 100 + self.n
type Cache = ephemeral { db: &Db, stmts: Vec[Stmt] }
impl Cache:
mut fn step(id: i32) -> i32:
self.stmts.push(Stmt { parent: self.db, n: id })
self.stmts[self.stmts.len() as i32 - 1].step()
fn Cache.over(db: &Db) -> Cache: Cache { db: db, stmts: Vec.new() }
fn main:
let db = Db { n: 1, live: true }
var cache = Cache.over(db)
let b = cache.step(11)
let c = cache.step(10)
print(f"{b} {c}")
Expected:111 110, then close db 1. Actual: exit 139. lldb: EXC_BAD_ACCESS (address=0x0) in Stmt.step (self.parent.n) on the second cache.step — the second statement's parent is null.
The same program with type Db { n: i32 } (no Drop) lowers copy _1.db and has no blank, and prints 111 110. So the &Db field of the mut self receiver is treated as a moved owned field and reset-on-move nulls the caller's cache.db.
Hypothesis, not yet the exact line:Sema.get_type_name (SemaCheck.w ~26093) returns the pointee's name for TY_REF/TY_PTR, and type_has_drop_impl (Sema.w ~5911) keys on get_type_name, so type_has_drop_impl(&Db) answers 1 whenever Db: Drop; type_needs_drop(&Db) follows. Some field-operand path in MirLower then picks move/reset for the field. Needs lldb on the branch that built move _1.db to confirm.
Impact: any ephemeral struct holding &P of a Drop type and creating children from that field in a mut fn corrupts itself — e.g. a statement cache over a modeled-C Database (D51 stage 6). Ownership/drop change: its own isolated batch with :drop-audit/:move-audit.
Workaround used: modeled-C stage 6's statement-cache fixture (test/behavior/behav_c_facade_statement_cache.w) reborrows the field explicitly, Statement.st_new(&*self.db, id), which lowers as a copy. A call argument (Stmt.p(self.db, id)) and a typed local (let db: &Db = self.db) crash the same way. Remove the reborrow when this is fixed.
Found while implementing modeled-C stage 6; not fixed there (out of scope).
Stage 6's PR #1519 adds type_owns_user_drop (Sema.w), a ref-blind twin of type_carries_user_drop, for the Rule 7 check: type_has_drop_impl(&W) answering as for W made a non-Drop view holding &Statement report as an implicit drop. The fix for this issue should make type_has_drop_impl/type_needs_drop stop at references and retire that twin.
Fixed by #1718 (Sema: type_has_drop_impl is false for TY_REF/TY_PTR, so a &P field is copied, not moved). Verified on main 3ccb998: the repro prints the expected 111 110 then close db 1, leak count=0.
Activity
Modeled C stage 6: `ok` on a dependent producer; `returns borrow` ren…
ehartford commentedon Sep 23, 2026
Stage 6's PR #1519 adds
type_owns_user_drop(Sema.w), a ref-blind twin oftype_carries_user_drop, for the Rule 7 check:type_has_drop_impl(&W)answering as forWmade a non-Drop view holding&Statementreport as an implicit drop. The fix for this issue should maketype_has_drop_impl/type_needs_dropstop at references and retire that twin.Modeled C stage 6: dependency (ruling §26-§30) (#1519)
Ownership: validate-ownership sees leaks (Reset state); drop exactly …
ehartford commentedon Sep 26, 2026
Fixed by #1718 (Sema: type_has_drop_impl is false for TY_REF/TY_PTR, so a
&Pfield is copied, not moved). Verified on main 3ccb998: the repro prints the expected111 110thenclose db 1, leak count=0.A package's interface records what was inferred: a view's origins, a …