[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <-MHKDYSM29ri6c9QKvSWSeFjWwM8yj6uNgAZ-2hMzY_vEokxnrcETWGTZtcNCmgmMwH4VLswDOtRWhjfVboo360PSTXxYjhiffD5B7CkkH0=@proton.me>
Date: Wed, 14 Jun 2023 19:04:52 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Gary Guo <gary@...yguo.net>
Cc: Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org,
Miguel Ojeda <ojeda@...nel.org>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
linux-kernel@...r.kernel.org, patches@...ts.linux.dev
Subject: Re: [PATCH] rust: make `UnsafeCell` the outer type in `Opaque`
> > /// 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
Powered by blists - more mailing lists