Skip to content

Commit 1f048f3

Browse files
nbdd0121mehmetb0
authored andcommitted
rust: enable arbitrary_self_types and remove Receiver
BugLink: https://bugs.launchpad.net/bugs/2096827 commit c95bbb5 upstream. 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 <[email protected]> Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> [koichiroden: dropped changes on rust/kernel/list/arc.rs due to missing commit: 6cd3417 ("rust: list: add ListArc")] Signed-off-by: Koichiro Den <[email protected]>
1 parent ecee422 commit 1f048f3

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

rust/kernel/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
//! do so first instead of bypassing this crate.
1313
1414
#![no_std]
15+
#![feature(arbitrary_self_types)]
1516
#![feature(coerce_unsized)]
1617
#![feature(dispatch_from_dyn)]
1718
#![feature(new_uninit)]
18-
#![feature(receiver_trait)]
1919
#![feature(unsize)]
2020

2121
// Ensure conditional compilation based on the kernel configuration works;

rust/kernel/sync/arc.rs

-6
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ impl<T: ?Sized> ArcInner<T> {
170170
}
171171
}
172172

173-
// This is to allow [`Arc`] (and variants) to be used as the type of `self`.
174-
impl<T: ?Sized> core::ops::Receiver for Arc<T> {}
175-
176173
// This is to allow coercion from `Arc<T>` to `Arc<U>` if `T` can be converted to the
177174
// dynamically-sized type (DST) `U`.
178175
impl<T: ?Sized + Unsize<U>, U: ?Sized> core::ops::CoerceUnsized<Arc<U>> for Arc<T> {}
@@ -501,9 +498,6 @@ pub struct ArcBorrow<'a, T: ?Sized + 'a> {
501498
_p: PhantomData<&'a ()>,
502499
}
503500

504-
// This is to allow [`ArcBorrow`] (and variants) to be used as the type of `self`.
505-
impl<T: ?Sized> core::ops::Receiver for ArcBorrow<'_, T> {}
506-
507501
// This is to allow `ArcBorrow<U>` to be dispatched on when `ArcBorrow<T>` can be coerced into
508502
// `ArcBorrow<U>`.
509503
impl<T: ?Sized + Unsize<U>, U: ?Sized> core::ops::DispatchFromDyn<ArcBorrow<'_, U>>

scripts/Makefile.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ $(obj)/%.lst: $(obj)/%.c FORCE
263263
# Compile Rust sources (.rs)
264264
# ---------------------------------------------------------------------------
265265

266-
rust_allowed_features := new_uninit
266+
rust_allowed_features := arbitrary_self_types,new_uninit
267267

268268
# `--out-dir` is required to avoid temporaries being created by `rustc` in the
269269
# current working directory, which may be not accessible in the out-of-tree

0 commit comments

Comments
 (0)