Skip to content

Commit

Permalink
rust: enable arbitrary_self_types and remove Receiver
Browse files Browse the repository at this point in the history
The `arbitrary_self_types` RFC [1] is accepted and the feature is being
worked on [2]. As part of the RFC, a new `Receiver` trait is to be added,
and it will be automatically implemented for all types that have `Deref`
implementation. This is different from the existing `Receiver` trait
that we use, which is a custom implementation that opts-in a type into
being 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.

Cc: Adrian Taylor <ade@hohum.me.uk>
Link: rust-lang/rfcs#3519 [1]
Link: rust-lang/rust#44874 [2]
Signed-off-by: Gary Guo <gary@garyguo.net>
  • Loading branch information
nbdd0121 authored and intel-lab-lkp committed Sep 10, 2024
1 parent 93dc3be commit 8ad4b94
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
//! do so first instead of bypassing this crate.

#![no_std]
#![feature(arbitrary_self_types)]
#![feature(coerce_unsized)]
#![feature(dispatch_from_dyn)]
#![feature(new_uninit)]
#![feature(receiver_trait)]
#![feature(unsize)]

// Ensure conditional compilation based on the kernel configuration works;
Expand Down
3 changes: 0 additions & 3 deletions rust/kernel/list/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,6 @@ where
}
}

// This is to allow [`ListArc`] (and variants) to be used as the type of `self`.
impl<T, const ID: u64> core::ops::Receiver for ListArc<T, ID> where T: ListArcSafe<ID> + ?Sized {}

// This is to allow coercion from `ListArc<T>` to `ListArc<U>` if `T` can be converted to the
// dynamically-sized type (DST) `U`.
impl<T, U, const ID: u64> core::ops::CoerceUnsized<ListArc<U, ID>> for ListArc<T, ID>
Expand Down
6 changes: 0 additions & 6 deletions rust/kernel/sync/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ impl<T: ?Sized> ArcInner<T> {
}
}

// This is to allow [`Arc`] (and variants) to be used as the type of `self`.
impl<T: ?Sized> core::ops::Receiver for Arc<T> {}

// This is to allow coercion from `Arc<T>` to `Arc<U>` if `T` can be converted to the
// dynamically-sized type (DST) `U`.
impl<T: ?Sized + Unsize<U>, U: ?Sized> core::ops::CoerceUnsized<Arc<U>> for Arc<T> {}
Expand Down Expand Up @@ -480,9 +477,6 @@ pub struct ArcBorrow<'a, T: ?Sized + 'a> {
_p: PhantomData<&'a ()>,
}

// This is to allow [`ArcBorrow`] (and variants) to be used as the type of `self`.
impl<T: ?Sized> core::ops::Receiver for ArcBorrow<'_, T> {}

// This is to allow `ArcBorrow<U>` to be dispatched on when `ArcBorrow<T>` can be coerced into
// `ArcBorrow<U>`.
impl<T: ?Sized + Unsize<U>, U: ?Sized> core::ops::DispatchFromDyn<ArcBorrow<'_, U>>
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ $(obj)/%.lst: $(obj)/%.c FORCE
# Compile Rust sources (.rs)
# ---------------------------------------------------------------------------

rust_allowed_features := new_uninit
rust_allowed_features := arbitrary_self_types,new_uninit

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

0 comments on commit 8ad4b94

Please sign in to comment.