Skip to content

let-else success path cancels the subject's drop instead of consuming it: validate-all reports a leak for a Copy-payload match #1750

Closed

Description

@ehartford

Spec: §9.7 (let ... else), §2.4 (every owned value dropped exactly once). Found while verifying #1384 on main 3ccb998.

fn items(k: i32) -> Result[i32, str]:
    if k == 0: return Err("none".clone())
    1
fn refutable(k: i32) -> i32:
    let Ok(v) = items(k) else: return -1
    v
fn main:
    print(f"{refutable(0)}")

run --debug-alloc: -1, leak count=0. check --validate-all: owned local _3 is still Init at return — no path drops or moves it (a leak).

MIR of refutable: the fail block drops _3 (#1365's fix), but the success block (bb4) neither drops nor consumes _3: lower_let_else cancels the subject's scheduled scope-exit drop on the success path (cancel_scheduled_value_drop_for_local). With a Copy payload nothing is owned on that variant, so there is no runtime leak today, but the MIR states an owned value that is never released, and the validator is right to reject it. With an owned payload the ignored parts are moved into temporaries and dropped, and the validator passes (it sees the moved sub-place).

Expected: the success path keeps the subject's scope-exit drop (moved-out fields are already blanked, so the drop frees only what remains); validate-all passes; the debug allocator stays at 0. Ownership change: battery with :drop-audit/:move-audit.

Activity

  1. added 5 commits that reference this issue on Sep 27, 2026
    e2bf693
    9b822e7
    68e3202
    9b787af
    bc01e9d
  2. added a commit that references this issue on Sep 27, 2026
    6dae0f0
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