Re: [PATCH v19 1/3] rust: types: add `ForeignOwnable::PointedTo`
From: Alice Ryhl
Date: Thu May 01 2025 - 03:17:55 EST
On Wed, Apr 30, 2025 at 8:57 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
>
> On Wed, Apr 30, 2025 at 11:31 AM Gary Guo <gary@xxxxxxxxxxx> wrote:
> >
> > On Wed, 23 Apr 2025 09:54:37 -0400
> > Tamir Duberstein <tamird@xxxxxxxxx> wrote:
> > > -impl<T: 'static, A> ForeignOwnable for Box<T, A>
> > > +// SAFETY: The `into_foreign` function returns a pointer that is well-aligned.
> > > +unsafe impl<T: 'static, A> ForeignOwnable for Box<T, A>
> > > where
> > > A: Allocator,
> > > {
> > > + type PointedTo = T;
> >
> > I don't think this is the correct solution for this. The returned
> > pointer is supposed to opaque, and exposing this type may encourage
> > this is to be wrongly used.
>
> Can you give an example?
This came up when we discussed this patch in the meeting yesterday:
https://lore.kernel.org/all/20250227-configfs-v5-1-c40e8dc3b9cd@xxxxxxxxxx/
This is incorrect use of the trait. The pointer is supposed to be
opaque, and you can't dereference it. See my reply to that patch as
well:
https://lore.kernel.org/all/CAH5fLggDwPBzMO2Z48oMjDm4qgoNM0NQs_63TxmVEGy+gtMpOA@xxxxxxxxxxxxxx/
Alice