From: "Benno Lossin" <lossin@kernel.org>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rust: sync: add `UniqueArc::as_ptr`
Date: Mon, 16 Feb 2026 11:12:29 +0100 [thread overview]
Message-ID: <DGGB0XJI8MAK.1HJI01HG3IBH9@kernel.org> (raw)
In-Reply-To: <87fr71duv2.fsf@t14s.mail-host-address-is-not-set>
On Mon Feb 16, 2026 at 8:13 AM CET, Andreas Hindborg wrote:
> "Benno Lossin" <lossin@kernel.org> writes:
>
>> On Sun Feb 15, 2026 at 9:38 PM CET, Andreas Hindborg wrote:
>>> Add a method to `UniqueArc` for getting a raw pointer. The implementation
>>> defers to the `Arc` implementation of the same method.
>>>
>>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>>> ---
>>> rust/kernel/sync/arc.rs | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
>>> index 289f77abf415a..9c70fdd39bd2f 100644
>>> --- a/rust/kernel/sync/arc.rs
>>> +++ b/rust/kernel/sync/arc.rs
>>> @@ -770,6 +770,11 @@ pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError>
>>> inner: unsafe { Arc::from_inner(KBox::leak(inner).into()) },
>>> })
>>> }
>>> +
>>> + /// Return a raw pointer to the data in this unique arc.
>>> + pub fn as_ptr(&self) -> *const T {
>>
>> This should be an associated function instead of an inherent method.
>
> I think this is so that we always call the function on the intended
> object rather than going through Deref. Could you please clarify if this
> is correct?
If you declare an inherent method on a type that is `Deref` (or
`Receiver`), then you can never call a method with the same name on the
object it derefs to:
struct MyThing;
impl MyThing {
fn as_ptr(&self) -> *const () { /* ... */ }
}
let my_thing = UniqueArc::new(MyThing);
let _: *const MyThing = my_thing.as_ptr(); // this is the method from `UniqueArc`
// to call the other one, we have to write:
let _: *const () = MyThing::my_thing(&*my_thing);
Especially a function with the name `as_ptr` should be associated, since
both very likely return a pointer; this increases the likelihood of
accidentally calling the wrong one.
Cheers,
Benno
next prev parent reply other threads:[~2026-02-16 10:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-15 20:38 [PATCH] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
2026-02-15 23:26 ` Benno Lossin
2026-02-16 7:13 ` Andreas Hindborg
2026-02-16 10:12 ` Benno Lossin [this message]
2026-02-16 1:38 ` Gary Guo
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=DGGB0XJI8MAK.1HJI01HG3IBH9@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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