Skip to main content

drop_shared_capture

Function drop_shared_capture 

Source
pub unsafe fn drop_shared_capture(
    layout: &ClosureLayout,
    base: *mut u8,
    i: usize,
)
Expand description

Release a Shared capture: read the cell pointer at the slot, decode the interior FieldKind, drop any heap refcount share carried by a Ptr payload, and finally Arc::from_raw + drop the cell to release its strong-count share.

This is the per-capture handler invoked by release_typed_closure’s dispatch on capture_storage_kind(i). The contract pairs with drop_owned_mutable_capture (defined by the parallel-track migration of owned-mutable storage) — both are reached only when the closure refcount has hit zero, and each handler is responsible for fully reclaiming its slot’s resources.

§Safety

  • base must point to a live TypedClosureHeader block whose layout matches layout, and capture i must be CaptureKind::Shared (mask bit shared_capture_mask & (1 << i) set).
  • The slot at base.add(layout.heap_capture_offset(i)) must contain a non-null *const SharedCell produced by Arc::into_raw on a freshly-allocated Arc<SharedCell> (or null, in which case the release is a no-op).
  • For Ptr interior kind the payload bits must be a valid ValueWord bit pattern for which release_raw_value_bits semantics apply.
  • After this call the slot must not be read again (the Arc::from_raw may have freed the underlying SharedCell).