Re: [PATCH v3] rust: sync: make AlwaysRefCounted::inc_ref an associated function

From: Andreas Hindborg

Date: Thu Nov 26 2026 - 05:55:48 EST


Tran Van Tien <7enlab@xxxxxxxxx> writes:

> In-Reply-To: <1795684556.6d661f19@xxxxxxxxx>
> References: <1795684556.6d661f19@xxxxxxxxx>
>
> Incrementing a reference count must be a deliberate act, and every
> inc_ref must be matched by exactly one dec_ref. Making inc_ref an
> associated function that takes a NonNull<Self> mirrors dec_ref, which
> is already an associated function because the object is freed when the
> count reaches zero.
>
> Having one half of the protocol take a reference and the other half a
> raw pointer makes the pairing harder to review and easier to get wrong.
>
> This was suggested by Benno Lossin.
>
> Suggested-by: Benno Lossin <lossin@xxxxxxxxxx>
> Link: https://github.com/Rust-for-Linux/linux/issues/1177
> Signed-off-by: Tran Van Tien <7enlab@xxxxxxxxx>

Please consider rate limiting your resend to at most 1 version every 24
hours.

Please consider using the b4 tool [1].

Best regards,
Andreas Hindborg

[1] https://b4.docs.kernel.org/en/latest/