rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: Gary Guo <gary@garyguo.net>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
	rust-for-linux@vger.kernel.org, "Miguel Ojeda" <ojeda@kernel.org>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	linux-kernel@vger.kernel.org, patches@lists.linux.dev
Subject: Re: [PATCH] rust: make `UnsafeCell` the outer type in `Opaque`
Date: Wed, 14 Jun 2023 19:04:52 +0000	[thread overview]
Message-ID: <-MHKDYSM29ri6c9QKvSWSeFjWwM8yj6uNgAZ-2hMzY_vEokxnrcETWGTZtcNCmgmMwH4VLswDOtRWhjfVboo360PSTXxYjhiffD5B7CkkH0=@proton.me> (raw)
In-Reply-To: <20230614194255.1fb8f6c0.gary@garyguo.net>

> > /// Gets the value behind `this`.
> > @@ -266,7 +266,7 @@ pub fn get(&self) -> *mut T {
> > /// This function is useful to get access to the value without creating intermediate
> > /// references.
> > pub const fn raw_get(this: *const Self) -> *mut T {
> > - UnsafeCell::raw_get(this.cast::<UnsafeCell<T>>())
> > + UnsafeCell::raw_get(this.cast::<UnsafeCell<MaybeUninit<T>>>()).cast::<T>()
> 
> 
> This can just be `this.cast_mut().cast()` since all types involved are
> transparent.

I would advise against that, see [1]. It would be bad for people to
assume that one is always allowed to do that. I also like it explicit here.

[1]: https://github.com/rust-lang/unsafe-code-guidelines/issues/281

--
Cheers,
Benno

  reply	other threads:[~2023-06-14 19:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14 11:53 [PATCH] rust: make `UnsafeCell` the outer type in `Opaque` Alice Ryhl
2023-06-14 14:27 ` Benno Lossin
2023-06-14 14:37   ` Alice Ryhl
2023-06-14 15:30 ` Martin Rodriguez Reboredo
2023-06-14 18:42 ` Gary Guo
2023-06-14 19:04   ` Benno Lossin [this message]
2023-08-09 23:21 ` Miguel Ojeda

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='-MHKDYSM29ri6c9QKvSWSeFjWwM8yj6uNgAZ-2hMzY_vEokxnrcETWGTZtcNCmgmMwH4VLswDOtRWhjfVboo360PSTXxYjhiffD5B7CkkH0=@proton.me' \
    --to=benno.lossin@proton.me \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --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=patches@lists.linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --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 NNTP newsgroup(s).