Re: [PATCH v3] rust: locks: Add `get_mut` method to `Lock`

From: Boqun Feng
Date: Sun Feb 25 2024 - 14:57:31 EST


On Sun, Feb 25, 2024 at 10:21:23AM +0100, Mathys Gasnier wrote:
> Should i include this comment in this patch ?
>

My suggestion is 1) in the comment of the `get_mut()` function, mention
that "`data` is not structurally pinned, so return a `&mut T` here" and
2) in the function body of `get_mut()`, at the safety comments, you only
need to put the reasoning explaining that `self` wouldn't get moved via
the return value of `self.get_unchecked_mut()`.

With these (along with the period and newline added), it'll be good to
me.

Regards,
Boqun

> Le ven. 23 févr. 2024 à 11:49, Alice Ryhl <aliceryhl@xxxxxxxxxx> a écrit :
>
> > On Fri, Feb 23, 2024 at 3:52 AM Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
> > > BTW, while we are at it, I think we should document the
> > > "structural/non-structural pinning" design decisions somewhere, for
> > > example in the struct definition:
> > >
> > > #[pin_data]
> > > pub struct Lock<T: ?Sized, B: Backend> {
> > > ...
> > > /// The data protected by the lock.
> > > /// This field is non-structural pinned.
> > > pub(crate) data: UnsafeCell<T>,
> > > }
> > >
> > > Thoughts? Or do we think "non-structural pinned" should be the default
> > > case so no need to document it? I want to have a clear document for each
> > > field to avoid the accidental "everyone forgets what's the decision
> > > here" ;-)
> >
> > I would normally assume that "field is not marked #[pin]" implies that
> > it's not structurally pinned. But it could still be worth to call out
> > here.
> >
> > I prefer the wording "not structurally pinnned" over "non-structural
> > pinned".
> >
> > Alice
> >