Thread (19 messages) 19 messages, 4 authors, 15d ago

Re: [PATCH v21 4/9] rust: rename `AlwaysRefCounted` to `RefCounted`.

From: Andreas Hindborg <a.hindborg@kernel.org>
Date: 2026-09-13 09:49:28
Also in: dri-devel, driver-core, linux-block, linux-fsdevel, linux-mm, linux-pci, linux-pwm, linux-security-module, linux-usb, lkml, rust-for-linux

"Gary Guo" [off-list ref] writes:
On Fri Sep 11, 2026 at 10:08 AM BST, Alice Ryhl wrote:
quoted
On Thu, Sep 10, 2026 at 11:01 AM Andreas Hindborg [off-list ref] wrote:
quoted
From: Oliver Mangold <redacted>

There are types where it may both be reference counted in some cases and
owned in others. In such cases, obtaining `ARef<T>` from `&T` would be
unsound as it allows creation of `ARef<T>` copy from `&Owned<T>`.

Therefore, we split `AlwaysRefCounted` into `RefCounted` (which `ARef<T>`
would require) and a marker trait to indicate that the type is always
reference counted (and not `Ownable`) so the `&T` -> `ARef<T>` conversion
is possible.

- Rename `AlwaysRefCounted` to `RefCounted`.
- Add a new unsafe trait `AlwaysRefCounted`.
- Implement the new trait `AlwaysRefCounted` for the newly renamed
  `RefCounted` implementations. This leaves functionality of existing
  implementers of `AlwaysRefCounted` intact.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Oliver Mangold <redacted>
[ Andreas: Updated commit message and rebase on rust-next (7.2) ]
Acked-by: Igor Korotin <redacted>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Assisted-by: LLM
Co-developed-by: Andreas Hindborg <a.hindborg@kernel.org>
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
This has a lot of safety comments of the form "This does not implement
Ownable, *therefore* it can implement AlwaysRefcounted". But I think
the safety comment should instead explain that it's okay to create an
ARef<_> from an &_ for this type. The fact that Ownable is not
implemented is not sufficient argument.

Alice
Yeah, I think for types that currently implement `AlwaysRefCounted` and does not
have a new `Ownable` form, it should keep saying that "this is always reference
counted".
Makes sense, I will fix them.

Best regards,
Andreas Hindborg


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help