Skip to content

MIR: a cancellation poll between argument calls resets the earlier argument temporaries instead of dropping them (ownership audit: "reset of _4 on a path where it was never moved") #2570

Closed

Description

@ehartford

Repro

A method that passes three callable values to a call, each produced by another call:

impl[K: Ord + Clone, V] BTreeMap[K, V]:
    fn prefix(entry: *mut u8) -> MlibSlotPrefix: mlib_slot_prefix(self.comparator(), self.cloner(), self.dropper(), entry)

with analyze <any program using BTreeMap> audit:all:

violation: ownership MIR: fn sym15651(BTreeMap.prefix__receiver__2886_3_3) stmt4 span=0: reset of _4 on a path where it was never moved: the value it holds is lost (§2.5.1)

The MIR

The cancellation polls (#2511: a callable parameter may suspend) between the argument calls give every cancel path a reset of the earlier argument temporaries instead of a drop:

fn sym15651(BTreeMap.prefix__receiver__2886_3_3) {
  locals:
    _0: ty282  // return [mut]
    _1: ty2891  // sym31 [caller-place]
    _2: ty279  // sym306
    _3: ty2891 [mut]
    _4: ty278 [mut]
    _5: ty2891 [mut]
    _6: ty280 [mut]
    _7: ty3 [mut]
    _8: ty3 [mut]
    _9: ty2891 [mut]
    _10: ty281 [mut]
    _11: ty282 [mut]
    _12: ty3 [mut]
    _13: ty3 [mut]

  bb0: {
    StorageLive(_1);
    StorageLive(_2);
    _3 = ref(shared, _1.*);
    call const fn sym298(copy _3) -> [return: _4, next: bb1];
  }

  bb1: {
    _5 = ref(shared, _1.*);
    call const fn sym300(copy _5) -> [return: _6, next: bb3];
  }

  bb2: {
    _9 = ref(shared, _1.*);
    call const fn sym310(copy _9) -> [return: _10, next: bb7];
  }

  bb3: {
    call const ()() -> [return: _7, next: bb4];
  }

  bb4: {
    switchInt(copy _7) -> [0: bb2, otherwise: bb5];
  }

  bb5: {
    call const ()() -> [return: _8, next: bb6];
  }

  bb6: {
    _4 = const zst(ty278);
    return;
  }

  bb7: {
    call const fn sym257(move _4, move _6, move _10, copy _2) -> [return: _11, next: bb9];
  }

  bb8: {
    _0 = move _11;
    _4 = const zst(ty278);
    _6 = const zst(ty280);
    _10 = const zst(ty281);
    _11 = const zst(ty282);
    return;
  }

  bb9: {
    call const ()() -> [return: _12, next: bb10];
  }

  bb10: {
    switchInt(copy _12) -> [0: bb8, otherwise: bb11];
  }

  bb11: {
    call const ()() -> [return: _13, next: bb12];
  }

  bb12: {
    _4 = const zst(ty278);
    _6 = const zst(ty280);
    _10 = const zst(ty281);
    return;
  }
}

bb6 (cancelled after the second argument) resets _4 (the first closure, never moved) and bb12 resets _4, _6, _10. The values are fn values without drop glue, so nothing leaks at runtime, but the MIR is wrong by its own rule (§2.5.1) and the audit, which the battery runs, is red. Binding the three results to lets first avoids it (the facade now does), which is a workaround, not a fix.

Expected

A cancel path drops the argument temporaries that are live at the poll (or ends their storage), never resets them.

Activity

  1. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    Fixed in #2580 (c7fa606): a pending reset is emitted only once its move has happened. A flush asks the body whether a statement since the statement frame opened reads or drops the local, or a call terminator passes it; an unwind between a call's argument evaluations drops a still-owned argument temporary instead of resetting it. The unwinding call's result is stated unwritten at that return (MirBody.note_unwritten_at_return) and the ownership validator's leak rule reads the fact. Fixture behav_2570 runs the program and audit:all.

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