Re: [PATCH] rust: make `UnsafeCell` the outer type in `Opaque`

From: Benno Lossin
Date: Wed Jun 14 2023 - 15:05:13 EST


> > /// 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