Rust-for-linux archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Trevor Gross <tmgross@umich.edu>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: stop using ptr_metadata feature
Date: Thu, 8 Feb 2024 15:31:15 +0100	[thread overview]
Message-ID: <CAH5fLgg07Fx0FrtK2nsEj=DR96WuhqVrWyJ-bBhXqFr9Caz6FA@mail.gmail.com> (raw)
In-Reply-To: <CALNs47t63qAU2OpokvN6KykT0_NKpDLTBQGhLm-+zsvR1pcUAQ@mail.gmail.com>

On Mon, Feb 5, 2024 at 10:02 PM Trevor Gross <tmgross@umich.edu> wrote:
>
> On Mon, Feb 5, 2024 at 3:19 AM Alice Ryhl <aliceryhl@google.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

      reply	other threads:[~2024-02-08 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05  9:18 [PATCH] rust: stop using ptr_metadata feature Alice Ryhl
2024-02-05 12:25 ` Benno Lossin
2024-02-05 13:54 ` Martin Rodriguez Reboredo
2024-02-05 21:02 ` Trevor Gross
2024-02-08 14:31   ` Alice Ryhl [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH5fLgg07Fx0FrtK2nsEj=DR96WuhqVrWyJ-bBhXqFr9Caz6FA@mail.gmail.com' \
    --to=aliceryhl@google.com \
    --cc=alex.gaynor@gmail.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).