[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH5fLgg07Fx0FrtK2nsEj=DR96WuhqVrWyJ-bBhXqFr9Caz6FA@mail.gmail.com>
Date: Thu, 8 Feb 2024 15:31:15 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Trevor Gross <tmgross@...ch.edu>
Cc: Miguel Ojeda <ojeda@...nel.org>, Wedson Almeida Filho <wedsonaf@...il.com>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: stop using ptr_metadata feature
On Mon, Feb 5, 2024 at 10:02 PM Trevor Gross <tmgross@...ch.edu> wrote:
>
> On Mon, Feb 5, 2024 at 3:19 AM Alice Ryhl <aliceryhl@...gle.com> wrote:
> > // SAFETY: The metadata of `T` and `ArcInner<T>` is the same because `ArcInner` is a struct
> > // with `T` as its last field.
> > //
> > // This is documented at:
> > // <https://doc.rust-lang.org/std/ptr/trait.Pointee.html>.
>
> The comment should be reworded, no more metadata and no unsafe block
> so it doesn't have to be SAFETY.
How about this?
// Pointer casts leave the metadata unchanged. This is okay because
the metadata of `T` and
// `ArcInner<T>` is the same since `ArcInner` is a struct with `T` as
its last field.
//
// This is documented at:
// <https://doc.rust-lang.org/std/ptr/trait.Pointee.html>.
> > - let metadata: <ArcInner<T> as Pointee>::Metadata =
> > - unsafe { core::mem::transmute_copy(&metadata) };
> > + let ptr = ptr as *mut ArcInner<T>;
>
> Nit: this could be `.cast::<ArcInner<T>>().cast_mut()` to make the
> intentional mutability change clear.
The `.cast()` method can't be used here. It only works for sized types.
Alice
Powered by blists - more mailing lists