[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230717134740.1840206-1-aliceryhl@google.com>
Date: Mon, 17 Jul 2023 13:47:40 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: benno.lossin@...ton.me
Cc: alex.gaynor@...il.com, aliceryhl@...gle.com,
bjorn3_gh@...tonmail.com, boqun.feng@...il.com, gary@...yguo.net,
jiangshanlai@...il.com, linux-kernel@...r.kernel.org,
ojeda@...nel.org, patches@...ts.linux.dev,
rust-for-linux@...r.kernel.org, tj@...nel.org,
walmeida@...rosoft.com, wedsonaf@...il.com
Subject: Re: [PATCH v3 2/9] rust: sync: add `Arc::{from_raw, into_raw}`
Benno Lossin <benno.lossin@...ton.me> 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
Powered by blists - more mailing lists