Skip to content

Bug: impl Drop with fn drop(self) / fn drop(mut self) fails codegen instead of a check-time diagnostic (§2.4) #642

Closed

Description

@ehartford

Summary

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.

Activity

  1. ehartford commented on Jul 4, 2026

    @ehartford
    ContributorAuthor

    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.

  2. ehartford commented on Jul 4, 2026

    @ehartford
    ContributorAuthor

    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.

  3. added a commit that references this issue on Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions