On Sun, Jan 18, 2026 at 12:19:35PM +0800, Boqun Feng wrote:
> On Sat, Jan 17, 2026 at 05:03:15PM +0000, Gary Guo wrote:
> > On Sat Jan 17, 2026 at 12:22 PM GMT, Boqun Feng wrote:
> > > +// SAFETY:
> > > +//
> > > +// - `*mut T` has the same size and alignment with `*const c_void`, and
> > > is round-trip
> > > +// transmutable to `*const c_void`.
> > > +// - `*mut T` is safe to transfer between execution contexts. See the
> > > safety requirement of
> > > +// [`AtomicType`].
> > > +unsafe impl<T: Sized> super::AtomicType for *mut T {
> > > + type Repr = *const c_void;
> > > +}
> >
> > How about *const T?
> >
>
> In general I want to avoid const raw pointers since it provides very
> little extra compared to mut raw pointers. For compiler optimization,
> provenenace is more important than "const vs mut" modifier, for
> dereference, it's unsafe anyway and users need to provide reasoning
> (including knowing the provenance and other accesses may happen to the
> same address), so I feel the type difference of "*const T" vs "*mut T"
> doesn't do anything extra either.
>
> Think about it, in Rust std, there are two pointer types only maps to
> "*mut T": NonNull<T> (as_ptr() returns a `*mut T`) and AtomicPtr<T>
> (as_ptr() returns a `*mut *mut T`). And there is no type like
> NonNullConst<T> and AtomicConstPtr<T>. This is a lint to me that we may
> not need to support `*const T` in most cases.
>
> But maybe I'm missing something? If you have a good reason, we can
> obviously add the support for `*const T`.
It was pretty inconvenient in:
https://lore.kernel.org/all/[email protected]/
since I had to cast_mut() a bunch of places.
Alice