Re: [PATCH v2 1/2] rust: atomic: add fetch_sub
From: Miguel Ojeda
Date: Thu Feb 19 2026 - 08:20:34 EST
On Thu, Feb 19, 2026 at 1:20 PM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> + fn fetch_sub[acquire, release, relaxed](a: &AtomicRepr<Self>, v: Self::Delta) -> Self {
> + // SAFETY: `a.as_ptr()` is valid and properly aligned.
> + unsafe { bindings::#call(v, a.as_ptr().cast()) }
> + }
[ I see `fetch_add` does the same, so it is fine here in this patch
for consistency, but I thought I would leave a note here anyway... ]
The safety comment, as written, could be read as just saying something
it is true without justifying it. Something like:
`a.as_ptr()` guarantees the returned pointer is valid and properly aligned.
would show better why it is such, rather than simply stating it.
Cheers,
Miguel