[PATCH v21 4/9] rust: rename `AlwaysRefCounted` to `RefCounted`.
Andreas Hindborg
a.hindborg at kernel.org
Sun Sep 13 09:49:12 UTC 2026
"Gary Guo" <gary at garyguo.net> writes:
> On Fri Sep 11, 2026 at 10:08 AM BST, Alice Ryhl wrote:
>> On Thu, Sep 10, 2026 at 11:01 AM Andreas Hindborg <a.hindborg at kernel.org> wrote:
>>>
>>> From: Oliver Mangold <oliver.mangold at pm.me>
>>>
>>> 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 at google.com>
>>> Reviewed-by: Daniel Almeida <daniel.almeida at collabora.com>
>>> Signed-off-by: Oliver Mangold <oliver.mangold at pm.me>
>>> [ Andreas: Updated commit message and rebase on rust-next (7.2) ]
>>> Acked-by: Igor Korotin <igor.korotin.linux at gmail.com>
>>> Acked-by: Danilo Krummrich <dakr at kernel.org>
>>> Acked-by: Viresh Kumar <viresh.kumar at linaro.org>
>>> Reviewed-by: Gary Guo <gary at garyguo.net>
>>> Assisted-by: LLM
>>> Co-developed-by: Andreas Hindborg <a.hindborg at kernel.org>
>>> Signed-off-by: Andreas Hindborg <a.hindborg at 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
More information about the Linux-security-module-archive
mailing list