Skip to content

Commit 2c20361

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 <[email protected]>
1 parent a298c5b commit 2c20361

4 files changed

Lines changed: 9 additions & 2 deletions

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> {}

scripts/Makefile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ $(obj)/%.lst: $(obj)/%.c FORCE
215215
# Compile Rust sources (.rs)
216216
# ---------------------------------------------------------------------------
217217

218-
rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,impl_trait_in_assoc_type,lint_reasons,type_alias_impl_trait
218+
rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,impl_trait_in_assoc_type,lint_reasons,pin_coerce_unsized_trait,type_alias_impl_trait
219219

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

0 commit comments

Comments
 (0)