[PATCH v22 4/5] rust: rename `AlwaysRefCounted` to `RefCounted`

sashiko-bot at kernel.org sashiko-bot at kernel.org
Tue Nov 17 14:23:01 UTC 2026


> 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. For such types, obtaining an `ARef<T>` from a `&T` may be
> unsound, as it allows creation of an `ARef<T>` from a `&Owned<T>`.
> 
> Therefore, we split `AlwaysRefCounted` into `RefCounted` (which `ARef<T>`
> would require) and a marker trait to indicate that the `&T` -> `ARef<T>`
> conversion is sound for the type. A type that implements `Ownable` may
> only implement the marker trait if it allows an `ARef<T>` to exist
> together with an `Owned<T>`.
> 
> - 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>
> Signed-off-by: Oliver Mangold <oliver.mangold at pm.me>
> [ Andreas: Updated commit message, rebased on v7.4-rc2, converted new
>   implementers, relaxed the `ForeignOwnable` bound for `ARef<T>`, updated
>   safety comments. ]
> 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>
> Co-developed-by: Andreas Hindborg <a.hindborg at kernel.org>
> Signed-off-by: Andreas Hindborg <a.hindborg at kernel.org>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-unique-ref-v22-0-12029383206d@kernel.org?part=4




More information about the Linux-security-module-archive mailing list