]> www.infradead.org Git - users/jedix/linux-maple.git/commit
rust: enable arbitrary_self_types and remove `Receiver`
authorGary Guo <gary@garyguo.net>
Sun, 15 Sep 2024 13:26:31 +0000 (14:26 +0100)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 7 Oct 2024 19:39:57 +0000 (21:39 +0200)
commitc95bbb59a9b22f9b838b15d28319185c1c884329
tree6e8959287f6702667801debae7e297e3cd36d2c9
parent1c71ddb310ad04ccec70441c7f17089514e3bab8
rust: enable arbitrary_self_types and remove `Receiver`

The term "receiver" means that a type can be used as the type of `self`,
and thus enables method call syntax `foo.bar()` instead of
`Foo::bar(foo)`. Stable Rust as of today (1.81) enables a limited
selection of types (primitives and types in std, e.g. `Box` and `Arc`)
to be used as receivers, while custom types cannot.

We want the kernel `Arc` type to have the same functionality as the Rust
std `Arc`, so we use the `Receiver` trait (gated behind `receiver_trait`
unstable feature) to gain the functionality.

The `arbitrary_self_types` RFC [1] (tracking issue [2]) is accepted and
it will allow all types that implement a new `Receiver` trait (different
from today's unstable trait) to be used as receivers. This trait will be
automatically implemented for all `Deref` types, which include our `Arc`
type, so we no longer have to opt-in to be used as receiver. To prepare
us for the change, remove the `Receiver` implementation and the
associated feature. To still allow `Arc` and others to be used as method
receivers, turn on `arbitrary_self_types` feature instead.

This feature gate is introduced in 1.23.0. It used to enable both
`Deref` types and raw pointer types to be used as receivers, but the
latter is now split into a different feature gate in Rust 1.83 nightly.
We do not need receivers on raw pointers so this change would not affect
us and usage of `arbitrary_self_types` feature would work for all Rust
versions that we support (>=1.78).

Cc: Adrian Taylor <ade@hohum.me.uk>
Link: https://github.com/rust-lang/rfcs/pull/3519
Link: https://github.com/rust-lang/rust/issues/44874
Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/lib.rs
rust/kernel/list/arc.rs
rust/kernel/sync/arc.rs
scripts/Makefile.build