From 5657c3a9faf6c1243cecc9314244c92bfcd1ecad Mon Sep 17 00:00:00 2001 From: Benno Lossin Date: Sat, 8 Mar 2025 11:04:43 +0000 Subject: rust: add `ZeroableOption` and implement it instead of `Zeroable` for `Option>` When making pin-init its own crate, `Zeroable` will no longer be defined by the kernel crate and thus implementing it for `Option>` is no longer possible due to the orphan rule. For this reason introduce a new `ZeroableOption` trait that circumvents this problem. Signed-off-by: Benno Lossin Reviewed-by: Fiona Behrens Reviewed-by: Andreas Hindborg Tested-by: Andreas Hindborg Link: https://lore.kernel.org/r/20250308110339.2997091-11-benno.lossin@proton.me Signed-off-by: Miguel Ojeda --- rust/kernel/alloc/kbox.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rust/kernel/alloc') diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs index 9861433559dc..07150c038e3f 100644 --- a/rust/kernel/alloc/kbox.rs +++ b/rust/kernel/alloc/kbox.rs @@ -15,7 +15,7 @@ use core::pin::Pin; use core::ptr::NonNull; use core::result::Result; -use crate::init::{InPlaceWrite, Init, PinInit, Zeroable}; +use crate::init::{InPlaceWrite, Init, PinInit, ZeroableOption}; use crate::init_ext::InPlaceInit; use crate::types::ForeignOwnable; @@ -104,7 +104,7 @@ pub type KVBox = Box; // // In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant and there // is no problem with a VTABLE pointer being null. -unsafe impl Zeroable for Option> {} +unsafe impl ZeroableOption for Box {} // SAFETY: `Box` is `Send` if `T` is `Send` because the `Box` owns a `T`. unsafe impl Send for Box -- cgit v1.2.3