[PATCH 2/5] rust: pin-init: internal: remove associated type of `HasInitData`
From: Gary Guo
Date: Wed Sep 23 2026 - 14:28:03 EST
There is only a single implementation, the associated type is not
necessary. Remove it, and rename `AllData` to `InitData` to be a more
meaningful name.
The single implementation also means that "unsafe" is redundant, so remove
it as well.
Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
---
rust/pin-init/src/__internal.rs | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/rust/pin-init/src/__internal.rs b/rust/pin-init/src/__internal.rs
index 51f6b40daa9e..15eca4869bc3 100644
--- a/rust/pin-init/src/__internal.rs
+++ b/rust/pin-init/src/__internal.rs
@@ -89,30 +89,31 @@ pub unsafe trait HasPinData {
fn __pin_data() -> Self::PinData;
}
-/// This trait is automatically implemented for every type. It aims to provide the same type
-/// inference help as `HasPinData`.
+/// This trait is automatically implemented for every type.
///
-/// # Safety
-///
-/// Only the `init` module is allowed to use this trait.
-pub unsafe trait HasInitData {
- type InitData;
-
- fn __init_data() -> Self::InitData;
+/// It aims to provide type inference help; `PATH::__init_data()` is would be able to retrieve an
+/// instance of `InitData<PATH<Generics>>` without having to mention the generics explicitly.
+pub trait HasInitData {
+ #[inline]
+ fn __init_data() -> InitData<Self> {
+ InitData(PhantomInvariant::new())
+ }
}
-pub struct AllData<T: ?Sized>(PhantomInvariant<T>);
+impl<T: ?Sized> HasInitData for T {}
+
+pub struct InitData<T: ?Sized>(PhantomInvariant<T>);
-impl<T: ?Sized> Clone for AllData<T> {
+impl<T: ?Sized> Clone for InitData<T> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
-impl<T: ?Sized> Copy for AllData<T> {}
+impl<T: ?Sized> Copy for InitData<T> {}
-impl<T: ?Sized> AllData<T> {
+impl<T: ?Sized> InitData<T> {
/// Type inference helper function.
#[inline(always)]
pub fn __make_closure<F, E>(self, f: F) -> F
@@ -123,16 +124,6 @@ pub fn __make_closure<F, E>(self, f: F) -> F
}
}
-// SAFETY: TODO.
-unsafe impl<T: ?Sized> HasInitData for T {
- type InitData = AllData<T>;
-
- #[inline]
- fn __init_data() -> Self::InitData {
- AllData(PhantomInvariant::new())
- }
-}
-
/// Stack initializer helper type. Use [`stack_pin_init`] instead of this primitive.
///
/// # Invariants
--
2.54.0