{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiaalgi6pmqfic64b2vsdenlgcnctdhe4pnvovsai5jon6ymtgl5ka",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mjk2n6w3zvs2"
  },
  "path": "/t/arc-increment-strong-count-design-question/24177#post_1",
  "publishedAt": "2026-04-15T12:29:37.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "Arc::increment_strong_count",
    "Arc::from_raw_in",
    "Arc::decrement_strong_count"
  ],
  "textContent": "I was reading docs of Arc::increment_strong_count and in the safety section I found requirement that raw pointer passed to the function must point to valid allocation created by _global allocator_.\n\n> The pointer must have been obtained through `Arc::into_raw` and must satisfy the same layout requirements specified in Arc::from_raw_in. The associated `Arc` instance must be valid (i.e. the strong count must be at least 1) for the duration of this method, and `ptr` must point to a block of memory allocated by the global allocator.\n\nThis requirement surprised me, so I looked into implementation and after going though `Arc::increment_strong_count_in` layer I found that the implementation basically just creates `Arc` from raw pointer and clones it:\n\n\n    // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop\n    let arc = unsafe { mem::ManuallyDrop::new(Arc::from_raw_in(ptr, alloc)) };\n    // Now increase refcount, but don't drop new refcount either\n    let _arc_clone: mem::ManuallyDrop<_> = arc.clone();\n\n\nWhy does the implementation of `Arc::increment_strong_count` simply not walk pointers and increment strong count directly? Requiring `alloc` to be passed into `Arc::increment_strong_count` seams overly constraining, since at no point the allocator is used at all.\n\nI understand why Arc::decrement_strong_count needs access to the allocator, as it needs to drop inner `T` and `ArcInner` when strong and weak counters go to 0. Was `Arc::increment_strong_count` designed in such way to keep symmetry with decrementing part? Or is there some safety invariant that I do not see, that would be violated if `Arc::increment_strong_count` would call `fetch_add` on the strong counter directly?",
  "title": "Arc::increment_strong_count design question"
}