From: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
To: aliceryhl@google.com
Cc: a.hindborg@kernel.org, alex.gaynor@gmail.com,
benno.lossin@proton.me, bjorn3_gh@protonmail.com,
boqun.feng@gmail.com, gary@garyguo.net,
linux-kernel@vger.kernel.org, longman@redhat.com,
mingo@redhat.com, ojeda@kernel.org, peterz@infradead.org,
rust-for-linux@vger.kernel.org, tmgross@umich.edu,
trintaeoitogc@gmail.com, will@kernel.org
Subject: Re: [PATCH] rust: sync: lock: Add Lock::get_mut()
Date: Mon, 3 Feb 2025 14:55:43 -0300 [thread overview]
Message-ID: <20250203175543.241946-1-trintaeoitogc@gmail.com> (raw)
In-Reply-To: <CAH5fLggJnaTD3_uc--eZfXMHurPab_Y_XuJOPcSk5oTeiyjbqQ@mail.gmail.com>
Alice Ryhl <aliceryhl@google.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
prev parent reply other threads:[~2025-02-03 17:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-31 15:59 Guilherme Giacomo Simoes
2025-02-03 9:21 ` Alice Ryhl
2025-02-03 17:55 ` Guilherme Giacomo Simoes [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250203175543.241946-1-trintaeoitogc@gmail.com \
--to=trintaeoitogc@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®