Skip to content

View escape: Mutex.set(&self, value) stores a reference (or a callback handle) into longer-lived storage unchecked #1778

Closed

Description

@ehartford

Found by the D71 facade work (#1611). A view passed to Mutex[T].set through &self escapes into storage that outlives it, and the checker accepts it:

type H = ephemeral { slot: Mutex[Option[&i32]] }
fn keep(h: &H):
    let x = 5
    h.slot.set(Some(&x))    // accepted; the stored reference dangles after keep returns

The same path lets a callback-scope handle (§16.2b.9) outlive its callback. Expected per §21.1 / D22: storing a view into a place requires the view's origin to outlive that place; this is refused. Mutex.set mutates through &self (interior mutability), which the view-escape check does not see as a store into the receiver.

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