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
Bug: impl Drop with fn drop(self) / fn drop(mut self) fails codegen instead of a check-time diagnostic (§2.4) #642
A Drop impl only codegens when the receiver is move self: Self. The self and mut self forms pass with check but then fail with run with a generic error: code generation failed and no location — instead of the clear check-time diagnostic the self: Self form already produces.
Repro
type Widget { id: i32 }
impl Drop for Widget:
fn drop(mut self) -> Unit: // or: fn drop(self) -> Unit:
()
fn use_it() -> Unit:
let w = Widget { id: 1 }
let _ = w.id
fn main:
use_it()
print("ok")
with check → ok
with run → error: code generation failed / error: run failed (no source location)
Behavior by receiver mode:
receiver
result
move self: Self
works
self
check ok, codegen fails
mut self
check ok, codegen fails
self: Self
clean check error: "method receiver requires an explicit mode: use 'self: &Self', 'mut self: Self', or 'move self: Self'"
Spec
§2.4: a destructor is impl Drop for Type: fn drop(self). The spec examples use fn drop(self) / fn drop(self: Self), so the accepted form for Drop::drop should be well-defined and either work or be rejected with a clear message — not silently pass check and die in codegen.
Fix direction
Either (a) accept fn drop(self) / fn drop(mut self) for a Drop impl and lower them like move self (the destructor always consumes), or (b) reject them at check time with the same "requires an explicit mode / Drop::drop must take move self: Self" diagnostic the self: Self case gets. A check-passing / run-failing split with no location is the worst outcome.
Found
Surfaced while investigating #641 (alloc.w destructors). Minimal repro above is with-independent.
BDFL ruling (2026-07-04): move self: Self is the ONLY legal Drop::drop receiver (a destructor always consumes — Vale-style). fn drop(self) and fn drop(mut self) in a Drop impl become CHECK-TIME errors with a fix-it suggesting move self: Self (today they pass check and die in codegen with no location). Spec §2.4's examples are corrected to move self: Self and a normative receiver note added.
Fixed in f57cc73: non-move receivers in a Drop impl are now a check-time error — Drop.drop receiver must be 'move self: Self' — a destructor always consumes (§2.4) — instead of a location-less codegen failure. Fixture: err_drop_impl_receiver_mode.w. Spec §2.4 examples were already corrected in 6f9160e.
Activity
ehartford commentedon Jul 4, 2026
BDFL ruling (2026-07-04):
move self: Selfis the ONLY legal Drop::drop receiver (a destructor always consumes — Vale-style).fn drop(self)andfn drop(mut self)in a Drop impl become CHECK-TIME errors with a fix-it suggestingmove self: Self(today they pass check and die in codegen with no location). Spec §2.4's examples are corrected tomove self: Selfand a normative receiver note added.docs: record BDFL soundness-tier rulings (2026-07-04)
ehartford commentedon Jul 4, 2026
Fixed in f57cc73: non-move receivers in a Drop impl are now a check-time error —
Drop.drop receiver must be 'move self: Self' — a destructor always consumes (§2.4)— instead of a location-less codegen failure. Fixture:err_drop_impl_receiver_mode.w. Spec §2.4 examples were already corrected in 6f9160e.Fix #641a/#641b/#642: mut-self borrows (incl. Drop types); explicit .…
Five compiler/stdlib defects from the examples/ survey (#1150) (#1284)