aboutsummaryrefslogtreecommitdiff
path: root/rust/kernel/init
diff options
context:
space:
mode:
authorBenno Lossin <[email protected]>2023-08-14 08:47:40 +0000
committerMiguel Ojeda <[email protected]>2023-08-21 14:31:49 +0200
commit1a8076ac6d83825bedb2050e67db0f2635acbb09 (patch)
tree63bf052855987033b3f1e72920f2a1a6cea31105 /rust/kernel/init
parent2e704f1883f5dd2f1380944c7d969c817fcd189e (diff)
rust: init: make `PinInit<T, E>` a supertrait of `Init<T, E>`
Remove the blanket implementation of `PinInit<T, E> for I where I: Init<T, E>`. This blanket implementation prevented custom types that implement `PinInit`. Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Gary Guo <[email protected]> Signed-off-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/kernel/init')
-rw-r--r--rust/kernel/init/__internal.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/rust/kernel/init/__internal.rs b/rust/kernel/init/__internal.rs
index 7abd1fb65e41..12e195061525 100644
--- a/rust/kernel/init/__internal.rs
+++ b/rust/kernel/init/__internal.rs
@@ -32,6 +32,18 @@ where
}
}
+// SAFETY: While constructing the `InitClosure`, the user promised that it upholds the
+// `__pinned_init` invariants.
+unsafe impl<T: ?Sized, F, E> PinInit<T, E> for InitClosure<F, T, E>
+where
+ F: FnOnce(*mut T) -> Result<(), E>,
+{
+ #[inline]
+ unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
+ (self.0)(slot)
+ }
+}
+
/// This trait is only implemented via the `#[pin_data]` proc-macro. It is used to facilitate
/// the pin projections within the initializers.
///