[PATCH v21 4/9] rust: rename `AlwaysRefCounted` to `RefCounted`.
Alice Ryhl
aliceryhl at google.com
Fri Sep 11 09:08:18 UTC 2026
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
More information about the Linux-security-module-archive
mailing list