[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250203175543.241946-1-trintaeoitogc@gmail.com>
Date: Mon, 3 Feb 2025 14:55:43 -0300
From: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
To: aliceryhl@...gle.com
Cc: a.hindborg@...nel.org,
alex.gaynor@...il.com,
benno.lossin@...ton.me,
bjorn3_gh@...tonmail.com,
boqun.feng@...il.com,
gary@...yguo.net,
linux-kernel@...r.kernel.org,
longman@...hat.com,
mingo@...hat.com,
ojeda@...nel.org,
peterz@...radead.org,
rust-for-linux@...r.kernel.org,
tmgross@...ch.edu,
trintaeoitogc@...il.com,
will@...nel.org
Subject: Re: [PATCH] rust: sync: lock: Add Lock::get_mut()
Alice Ryhl <aliceryhl@...gle.com> wrotes:
> I maintain my objection that this function cannot be correctly called.
> Yes, if you use dubious unsafe code, you can call it, but we shouldn't
> do that.
>
> At best, you could change this method to take `self: Pin<&mut Self>`.
Yes you is right, we should avoid unsafe code. But how the
`self: Pin<&mut Self` help us here?
The unsafe code at the get_mut() call place, is because of
`get_unchecked_mut`. You probably already know, but this is unsafe because you
need guarantee that the value is not move in memory. The `get_unchecked_mut`
return a &mut T, (in this case return a &mut Example), and we need a reference
to Example for access `d` field.
since we have access for `d` , we can get get_mut() without pinned `d`.
We need a way for get `Example.d` without `get_unchecked_mut`.
Thanks,
Guilherme
Powered by blists - more mailing lists