Skip to content

Commit b862aac

Browse files
onestackedBennoLossin
authored andcommitted
rust: pin-init: Implement Wrapper for UnsafePinned behind feature flag.
Add the `unsafe-pinned` feature which gates the `Wrapper` implementation of the `core::pin::UnsafePinned` struct. For now this is just a cargo feature, but once `core::pin::UnsafePinned` is stable a config flag can be added to allow the usage of this implementation in the linux kernel. Signed-off-by: Christian Schrefl <chrisi.schrefl@gmail.com> Link: Rust-for-Linux/pin-init@99cb193 [ Fixed commit authorship. - Benno ] Signed-off-by: Benno Lossin <benno.lossin@proton.me>
1 parent 2f7c738 commit b862aac

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rust/pin-init/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@
269269
#![forbid(missing_docs, unsafe_op_in_unsafe_fn)]
270270
#![cfg_attr(not(feature = "std"), no_std)]
271271
#![cfg_attr(feature = "alloc", feature(allocator_api))]
272+
#![cfg_attr(
273+
all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED),
274+
feature(unsafe_pinned)
275+
)]
272276

273277
use core::{
274278
cell::UnsafeCell,
@@ -1557,3 +1561,11 @@ impl<T> Wrapper<T> for MaybeUninit<T> {
15571561
unsafe { cast_pin_init(value_init) }
15581562
}
15591563
}
1564+
1565+
#[cfg(all(feature = "unsafe-pinned", CONFIG_RUSTC_HAS_UNSAFE_PINNED))]
1566+
impl<T> Wrapper<T> for core::pin::UnsafePinned<T> {
1567+
fn pin_init<E>(init: impl PinInit<T, E>) -> impl PinInit<Self, E> {
1568+
// SAFETY: `UnsafePinned<T>` has a compatible layout to `T`.
1569+
unsafe { cast_pin_init(init) }
1570+
}
1571+
}

0 commit comments

Comments
 (0)