Re: [PATCH v3 2/9] rust: sync: add `Arc::{from_raw, into_raw}`

From: Alice Ryhl
Date: Mon Jul 17 2023 - 09:48:09 EST


Benno Lossin <benno.lossin@xxxxxxxxx> writes:
>> + /// This code relies on the `repr(C)` layout of structs as described in
>> + /// <https://doc.rust-lang.org/reference/type-layout.html#reprc-structs>.
>
> Why is this in the documentation? I feel like it should be a normal code
> comment at the very start of the function.

In fact, I think we can drop this comment entirely. The motivation
behind using `Layout::extend` for computing `val_offset` is that its
correctness does not rely on how the repr(C) layout algorithm works.

(As opposed to how the previous implementation's correctness *does*
depend on knowing the repr(C) layout algorithm:
Layout::new::<ArcInner<()>>().align_to(align).unwrap().pad_to_align().size()
)

>> + ///
>> + /// # Safety
>> + ///
>> + /// `ptr` must have been returned by a previous call to [`Arc::into_raw`]. Additionally, it
>> + /// can only be called once for each previous call to [`Arc::into_raw`].
>
> "it can only" -> "it must only"

Sounds good. I'll change it to use "must" in the next version.

Alice