From: Gary Guo <gary@garyguo.net>
To: "Benno Lossin" <lossin@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
Gary Guo <gary@garyguo.net>
Subject: [PATCH 2/5] rust: pin-init: internal: remove associated type of `HasInitData`
Date: Wed, 23 Sep 2026 19:20:15 +0100 [thread overview]
Message-ID: <20260923-dev-pin-data-diag-v1-2-e4d7193569e5@garyguo.net> (raw)
In-Reply-To: <20260923-dev-pin-data-diag-v1-0-e4d7193569e5@garyguo.net>
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@garyguo.net>
---
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
next prev parent reply other threads:[~2026-09-23 18:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 18:20 [PATCH 0/5] rust: pin-init: improve diagnostics of missing `#[pin_data]` and `#[pin]` Gary Guo
2026-09-23 18:20 ` [PATCH 1/5] rust: pin-init: internal: make `__init_data` and `__pin_data` safe Gary Guo
2026-09-23 18:20 ` Gary Guo [this message]
2026-09-23 18:20 ` [PATCH 3/5] rust: pin-init: internal: use `HasInitData` to provide inference help only Gary Guo
2026-09-23 18:20 ` [PATCH 4/5] rust: pin-init: internal: add custom diagnostic when `#[pin_data]` is not implemented Gary Guo
2026-09-23 18:20 ` [PATCH 5/5] rust: pin-init: add diagnostic attribute for `PinInit` and `Init` Gary Guo
2026-09-25 20:41 ` [PATCH 0/5] rust: pin-init: improve diagnostics of missing `#[pin_data]` and `#[pin]` Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260923-dev-pin-data-diag-v1-2-e4d7193569e5@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®