Skip to content

Commit 5b30d62

Browse files
committed
rust: kernel: {arc, kbox}: use pin_coerce_unsized_trait
Required by the asahi driver for its driver data. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 3ee6f0b commit 5b30d62

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

rust/kernel/alloc/kbox.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ use crate::types::ForeignOwnable;
6565
/// `self.0` is always properly aligned and either points to memory allocated with `A` or, for
6666
/// zero-sized types, is a dangling, well aligned pointer.
6767
#[repr(transparent)]
68-
pub struct Box<T: ?Sized, A: Allocator>(NonNull<T>, PhantomData<A>);
68+
#[cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, derive(core::marker::CoercePointee))]
69+
pub struct Box<#[pointee] T: ?Sized, A: Allocator>(NonNull<T>, PhantomData<A>);
6970

7071
/// Type alias for [`Box`] with a [`Kmalloc`] allocator.
7172
///

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(arbitrary_self_types)]
1616
#![feature(associated_type_defaults)]
1717
#![cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, feature(derive_coerce_pointee))]
18+
#![cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, feature(pin_coerce_unsized_trait))]
1819
#![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(coerce_unsized))]
1920
#![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(dispatch_from_dyn))]
2021
#![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(unsize))]

rust/kernel/sync/arc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ impl<T: ?Sized> ArcInner<T> {
199199
#[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))]
200200
impl<T: ?Sized + core::marker::Unsize<U>, U: ?Sized> core::ops::CoerceUnsized<Arc<U>> for Arc<T> {}
201201

202+
// This is to allow coercion from `Arc<T>` to `Arc<U>` if `T` can be converted to the
203+
// dynamically-sized type (DST) `U`.
204+
#[cfg(CONFIG_RUSTC_HAS_COERCE_POINTEE)]
205+
unsafe impl<T: ?Sized> core::pin::PinCoerceUnsized for Arc<T> {}
206+
202207
// This is to allow `Arc<U>` to be dispatched on when `Arc<T>` can be coerced into `Arc<U>`.
203208
#[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))]
204209
impl<T: ?Sized + core::marker::Unsize<U>, U: ?Sized> core::ops::DispatchFromDyn<Arc<U>> for Arc<T> {}

0 commit comments

Comments
 (0)