Skip to contentSkip to conversation

rust: pin-init: rename `project` -> `project_this` in doctest

PATCH Applied Benno Lossin 4 participants 13 messages Sep 5, 2025 – Sep 11, 2025

Subsystems (2)
lore
Share & tools
lore

Benno Lossin

author maintainer
#0 lore raw

PATCH 1/2 rust: pin-init: rename `project` -> `project_this` in doctest

The next commit makes the #[pin_data] attribute generate a project function that would collide with any existing ones.

---
 rust/pin-init/src/lib.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/pin-init/src/lib.rs +1 -1
index 62e013a5cc20..2d0d9fd12524 100644
@@ -994,7 +994,7 @@ macro_rules! try_init {
 /// }
 ///
 /// impl<T> Foo<T> {
-///     fn project(self: Pin<&mut Self>) -> Pin<&mut T> {
+///     fn project_this(self: Pin<&mut Self>) -> Pin<&mut T> {
 ///         assert_pinned!(Foo<T>, elem, T, inline);
 ///
 ///         // SAFETY: The field is structurally pinned.

base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585

Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH 2/2 rust: pin-init: add pin projections to `#[pin_data]`

Make the #[pin_data] macro generate a *Projection struct that holds either Pin<&mut Field> or &mut Field for every field of the original struct. Which version is chosen depends on weather there is a #[pin] or not respectively. Access to this projected version is enabled through generating fn project(self: Pin<&mut Self>) -> SelfProjection<'_>.

[ Adapt workqueue to use the new projection instead of its own, custom
one - Benno ]

---
 rust/kernel/workqueue.rs    | 10 ++-----
 rust/pin-init/src/macros.rs | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 8 deletions(-)
rust/kernel/workqueue.rs +2 -8
index b9343d5bc00f..6ca14c629643 100644
@@ -356,18 +356,12 @@ struct ClosureWork<T> {
     func: Option<T>,
 }
 
-impl<T> ClosureWork<T> {
-    fn project(self: Pin<&mut Self>) -> &mut Option<T> {
-        // SAFETY: The `func` field is not structurally pinned.
-        unsafe { &mut self.get_unchecked_mut().func }
-    }
-}
-
 impl<T: FnOnce()> WorkItem for ClosureWork<T> {
     type Pointer = Pin<KBox<Self>>;
 
     fn run(mut this: Pin<KBox<Self>>) {
-        if let Some(func) = this.as_mut().project().take() {
+        if let Some(func) = this.as_mut().project().func.take() {
+            // if let Some(func) = this.as_mut().project_func().take() {
             (func)()
         }
     }
rust/pin-init/src/macros.rs +60 -0

72 lines not on this page · raw message

Signature · 1 line
2.50.1
reviewer
#2 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

Quoted 70 lines · Benno Lossin

Make the #[pin_data] macro generate a *Projection struct that holds either Pin<&mut Field> or &mut Field for every field of the original struct. Which version is chosen depends on weather there is a #[pin] or not respectively. Access to this projected version is enabled through generating fn project(self: Pin<&mut Self>) -> SelfProjection<'_>.

[ Adapt workqueue to use the new projection instead of its own, custom
one - Benno ]

---
 rust/kernel/workqueue.rs    | 10 ++-----
 rust/pin-init/src/macros.rs | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 8 deletions(-)
rust/kernel/workqueue.rs +2 -8
index b9343d5bc00f..6ca14c629643 100644
@@ -356,18 +356,12 @@ struct ClosureWork<T> {
     func: Option<T>,
 }
 
-impl<T> ClosureWork<T> {
-    fn project(self: Pin<&mut Self>) -> &mut Option<T> {
-        // SAFETY: The `func` field is not structurally pinned.
-        unsafe { &mut self.get_unchecked_mut().func }
-    }
-}
-
 impl<T: FnOnce()> WorkItem for ClosureWork<T> {
     type Pointer = Pin<KBox<Self>>;
 
     fn run(mut this: Pin<KBox<Self>>) {
-        if let Some(func) = this.as_mut().project().take() {
+        if let Some(func) = this.as_mut().project().func.take() {
+            // if let Some(func) = this.as_mut().project_func().take() {
             (func)()
         }
     }
rust/pin-init/src/macros.rs +14 -0
index 9ced630737b8..d225cc144904 100644
@@ -831,6 +831,17 @@ macro_rules! __pin_data {
             $($fields)*
         }
 
+        $crate::__pin_data!(make_pin_projections:
+            @vis($vis),
+            @name($name),
+            @impl_generics($($impl_generics)*),
+            @ty_generics($($ty_generics)*),
+            @decl_generics($($decl_generics)*),
+            @where($($whr)*),
+            @pinned($($pinned)*),
+            @not_pinned($($not_pinned)*),
+        );
+
         // We put the rest into this const item, because it then will not be accessible to anything
         // outside.
         const _: () = {
@@ -980,6 +991,55 @@ fn drop(&mut self) {
             stringify!($($rest)*),
         );
     };
+    (make_pin_projections:
+        @vis($vis:vis),
+        @name($name:ident),

rust/pin-init/src/macros.rs fn drop(&mut self) { · line 1006

Quoted 10 lines
rust/pin-init/src/macros.rs +10 -0
+        @impl_generics($($impl_generics:tt)*),
+        @ty_generics($($ty_generics:tt)*),
+        @decl_generics($($decl_generics:tt)*),
+        @where($($whr:tt)*),
+        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
+        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
+    ) => {
+        $crate::macros::paste! {
+            #[doc(hidden)]
+            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {

I'm not sure we want $vis here. That's the visibility of the original struct, but I don't think we want it to be pub just because the struct is.

Otherwise looks reasonable.

Alice

reviewer
#3 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

Quoted 36 lines · Alice Ryhl
Quoted 34 lines · Benno Lossin

Make the #[pin_data] macro generate a *Projection struct that holds either Pin<&mut Field> or &mut Field for every field of the original struct. Which version is chosen depends on weather there is a #[pin] or not respectively. Access to this projected version is enabled through generating fn project(self: Pin<&mut Self>) -> SelfProjection<'_>.

[ Adapt workqueue to use the new projection instead of its own, custom
one - Benno ]

---
 rust/kernel/workqueue.rs    | 10 ++-----
 rust/pin-init/src/macros.rs | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 8 deletions(-)
rust/kernel/workqueue.rs +0 -7
index b9343d5bc00f..6ca14c629643 100644
@@ -356,18 +356,12 @@ struct ClosureWork<T> {
     func: Option<T>,
 }
 
-impl<T> ClosureWork<T> {
-    fn project(self: Pin<&mut Self>) -> &mut Option<T> {
-        // SAFETY: The `func` field is not structurally pinned.
-        unsafe { &mut self.get_unchecked_mut().func }
-    }
-}
-
 impl<T: FnOnce()> WorkItem for ClosureWork<T> {
     type Pointer = Pin<KBox<Self>>;
 
Quoted 4 lines

rust/kernel/workqueue.rs struct ClosureWork<T> { · line 364

Quoted 4 lines
rust/kernel/workqueue.rs +2 -1
     fn run(mut this: Pin<KBox<Self>>) {
-        if let Some(func) = this.as_mut().project().take() {
+        if let Some(func) = this.as_mut().project().func.take() {
+            // if let Some(func) = this.as_mut().project_func().take() {

Spurious comment.

author maintainer
#4 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

Quoted 37 lines · Alice Ryhl
Quoted 36 lines · Alice Ryhl
Quoted 34 lines · Benno Lossin

Make the #[pin_data] macro generate a *Projection struct that holds either Pin<&mut Field> or &mut Field for every field of the original struct. Which version is chosen depends on weather there is a #[pin] or not respectively. Access to this projected version is enabled through generating fn project(self: Pin<&mut Self>) -> SelfProjection<'_>.

[ Adapt workqueue to use the new projection instead of its own, custom
one - Benno ]

---
 rust/kernel/workqueue.rs    | 10 ++-----
 rust/pin-init/src/macros.rs | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 8 deletions(-)
rust/kernel/workqueue.rs +0 -7
index b9343d5bc00f..6ca14c629643 100644
@@ -356,18 +356,12 @@ struct ClosureWork<T> {
     func: Option<T>,
 }
 
-impl<T> ClosureWork<T> {
-    fn project(self: Pin<&mut Self>) -> &mut Option<T> {
-        // SAFETY: The `func` field is not structurally pinned.
-        unsafe { &mut self.get_unchecked_mut().func }
-    }
-}
-
 impl<T: FnOnce()> WorkItem for ClosureWork<T> {
     type Pointer = Pin<KBox<Self>>;
 
Quoted 6 lines
Quoted 4 lines

rust/kernel/workqueue.rs struct ClosureWork<T> { · line 364

Quoted 4 lines
rust/kernel/workqueue.rs +2 -1
     fn run(mut this: Pin<KBox<Self>>) {
-        if let Some(func) = this.as_mut().project().take() {
+        if let Some(func) = this.as_mut().project().func.take() {
+            // if let Some(func) = this.as_mut().project_func().take() {

Spurious comment.

Oh yeah, will remove on apply.

---
Cheers,
Benno

author maintainer
#5 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

In reply to Alice Ryhl
Quoted 77 lines · Alice Ryhl
Quoted 76 lines · Benno Lossin

Make the #[pin_data] macro generate a *Projection struct that holds either Pin<&mut Field> or &mut Field for every field of the original struct. Which version is chosen depends on weather there is a #[pin] or not respectively. Access to this projected version is enabled through generating fn project(self: Pin<&mut Self>) -> SelfProjection<'_>.

[ Adapt workqueue to use the new projection instead of its own, custom
one - Benno ]

---
 rust/kernel/workqueue.rs    | 10 ++-----
 rust/pin-init/src/macros.rs | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 8 deletions(-)
rust/kernel/workqueue.rs +2 -8
index b9343d5bc00f..6ca14c629643 100644
@@ -356,18 +356,12 @@ struct ClosureWork<T> {
     func: Option<T>,
 }
 
-impl<T> ClosureWork<T> {
-    fn project(self: Pin<&mut Self>) -> &mut Option<T> {
-        // SAFETY: The `func` field is not structurally pinned.
-        unsafe { &mut self.get_unchecked_mut().func }
-    }
-}
-
 impl<T: FnOnce()> WorkItem for ClosureWork<T> {
     type Pointer = Pin<KBox<Self>>;
 
     fn run(mut this: Pin<KBox<Self>>) {
-        if let Some(func) = this.as_mut().project().take() {
+        if let Some(func) = this.as_mut().project().func.take() {
+            // if let Some(func) = this.as_mut().project_func().take() {
             (func)()
         }
     }
rust/pin-init/src/macros.rs +20 -0
index 9ced630737b8..d225cc144904 100644
@@ -831,6 +831,17 @@ macro_rules! __pin_data {
             $($fields)*
         }
 
+        $crate::__pin_data!(make_pin_projections:
+            @vis($vis),
+            @name($name),
+            @impl_generics($($impl_generics)*),
+            @ty_generics($($ty_generics)*),
+            @decl_generics($($decl_generics)*),
+            @where($($whr)*),
+            @pinned($($pinned)*),
+            @not_pinned($($not_pinned)*),
+        );
+
         // We put the rest into this const item, because it then will not be accessible to anything
         // outside.
         const _: () = {
@@ -980,6 +991,55 @@ fn drop(&mut self) {
             stringify!($($rest)*),
         );
     };
+    (make_pin_projections:
+        @vis($vis:vis),
+        @name($name:ident),
+        @impl_generics($($impl_generics:tt)*),
+        @ty_generics($($ty_generics:tt)*),
+        @decl_generics($($decl_generics:tt)*),
+        @where($($whr:tt)*),
+        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
+        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
Quoted 8 lines

rust/pin-init/src/macros.rs fn drop(&mut self) { · line 1006

Quoted 4 lines
rust/pin-init/src/macros.rs +4 -0
+    ) => {
+        $crate::macros::paste! {
+            #[doc(hidden)]
+            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {

I'm not sure we want $vis here. That's the visibility of the original struct, but I don't think we want it to be pub just because the struct is.

Why shouldn't it be pub if the original is pub? I don't really understand the concern, since the fields themselves will still have the correct visibility. Additionally, there is the ___pin_phantom_data field that's always private, so you cannot construct this outside of the module.

---
Cheers,
Benno

reviewer
#6 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

Quoted 21 lines · Benno Lossin
Quoted 15 lines · Alice Ryhl

rust/pin-init/src/macros.rs fn drop(&mut self) { · line 1006

Quoted 13 lines · Benno Lossin
rust/pin-init/src/macros.rs +13 -0
+    (make_pin_projections:
+        @vis($vis:vis),
+        @name($name:ident),
+        @impl_generics($($impl_generics:tt)*),
+        @ty_generics($($ty_generics:tt)*),
+        @decl_generics($($decl_generics:tt)*),
+        @where($($whr:tt)*),
+        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
+        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
+    ) => {
+        $crate::macros::paste! {
+            #[doc(hidden)]
+            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {
Quoted 3 lines

I'm not sure we want $vis here. That's the visibility of the original struct, but I don't think we want it to be pub just because the struct is.

Quoted 5 lines

Why shouldn't it be pub if the original is pub? I don't really understand the concern, since the fields themselves will still have the correct visibility. Additionally, there is the ___pin_phantom_data field that's always private, so you cannot construct this outside of the module.

I mean, for instance, it's going to mean that every single struct that wraps Opaque in a private field will get a useless pub function called project that will appear in html docs.

Pin-project limits the visibility to pub(crate) when the struct is pub.

Alice

author maintainer
#7 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

Quoted 28 lines · Alice Ryhl
Quoted 21 lines · Benno Lossin
Quoted 15 lines · Alice Ryhl

rust/pin-init/src/macros.rs fn drop(&mut self) { · line 1006

Quoted 13 lines · Benno Lossin
rust/pin-init/src/macros.rs +13 -0
+    (make_pin_projections:
+        @vis($vis:vis),
+        @name($name:ident),
+        @impl_generics($($impl_generics:tt)*),
+        @ty_generics($($ty_generics:tt)*),
+        @decl_generics($($decl_generics:tt)*),
+        @where($($whr:tt)*),
+        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
+        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
+    ) => {
+        $crate::macros::paste! {
+            #[doc(hidden)]
+            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {
Quoted 3 lines

I'm not sure we want $vis here. That's the visibility of the original struct, but I don't think we want it to be pub just because the struct is.

Quoted 5 lines

Why shouldn't it be pub if the original is pub? I don't really understand the concern, since the fields themselves will still have the correct visibility. Additionally, there is the ___pin_phantom_data field that's always private, so you cannot construct this outside of the module.

Quoted 3 lines

I mean, for instance, it's going to mean that every single struct that wraps Opaque in a private field will get a useless pub function called project that will appear in html docs.

It's #[doc(hidden)] :)

Quoted 1 line

Pin-project limits the visibility to pub(crate) when the struct is pub.

I think I would have to look inside the vis to recreate that behavior, so I'd rather do it as a future patch. Thoughts?

---
Cheers,
Benno

reviewer
#8 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

Quoted 34 lines · Benno Lossin
Quoted 28 lines · Alice Ryhl
Quoted 21 lines · Benno Lossin
Quoted 15 lines · Alice Ryhl

rust/pin-init/src/macros.rs fn drop(&mut self) { · line 1006

Quoted 13 lines · Benno Lossin
rust/pin-init/src/macros.rs +13 -0
+    (make_pin_projections:
+        @vis($vis:vis),
+        @name($name:ident),
+        @impl_generics($($impl_generics:tt)*),
+        @ty_generics($($ty_generics:tt)*),
+        @decl_generics($($decl_generics:tt)*),
+        @where($($whr:tt)*),
+        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
+        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
+    ) => {
+        $crate::macros::paste! {
+            #[doc(hidden)]
+            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {
Quoted 3 lines

I'm not sure we want $vis here. That's the visibility of the original struct, but I don't think we want it to be pub just because the struct is.

Quoted 5 lines

Why shouldn't it be pub if the original is pub? I don't really understand the concern, since the fields themselves will still have the correct visibility. Additionally, there is the ___pin_phantom_data field that's always private, so you cannot construct this outside of the module.

Quoted 3 lines

I mean, for instance, it's going to mean that every single struct that wraps Opaque in a private field will get a useless pub function called project that will appear in html docs.

Quoted 6 lines

It's #[doc(hidden)] :)

Quoted 1 line

Pin-project limits the visibility to pub(crate) when the struct is pub.

I think I would have to look inside the vis to recreate that behavior, so I'd rather do it as a future patch. Thoughts?

You could make the struct and method always pub(crate)?

Alice

author maintainer
#9 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

Quoted 35 lines · Alice Ryhl
Quoted 34 lines · Benno Lossin
Quoted 31 lines · Alice Ryhl
Quoted 21 lines · Benno Lossin
Quoted 15 lines · Alice Ryhl

rust/pin-init/src/macros.rs fn drop(&mut self) { · line 1006

Quoted 13 lines · Benno Lossin
rust/pin-init/src/macros.rs +13 -0
+    (make_pin_projections:
+        @vis($vis:vis),
+        @name($name:ident),
+        @impl_generics($($impl_generics:tt)*),
+        @ty_generics($($ty_generics:tt)*),
+        @decl_generics($($decl_generics:tt)*),
+        @where($($whr:tt)*),
+        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
+        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
+    ) => {
+        $crate::macros::paste! {
+            #[doc(hidden)]
+            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {
Quoted 3 lines

I'm not sure we want $vis here. That's the visibility of the original struct, but I don't think we want it to be pub just because the struct is.

Quoted 5 lines

Why shouldn't it be pub if the original is pub? I don't really understand the concern, since the fields themselves will still have the correct visibility. Additionally, there is the ___pin_phantom_data field that's always private, so you cannot construct this outside of the module.

I mean, for instance, it's going to mean that every single struct that wraps Opaque in a private field will get a useless pub function called project that will appear in html docs.

Quoted 8 lines
Quoted 6 lines

It's #[doc(hidden)] :)

Quoted 1 line

Pin-project limits the visibility to pub(crate) when the struct is pub.

I think I would have to look inside the vis to recreate that behavior, so I'd rather do it as a future patch. Thoughts?

You could make the struct and method always pub(crate)?

That doesn't work for module-private structs though?

---
Cheers,
Benno

Reviewed-by
#10 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

In reply to Benno Lossin
Quoted 33 lines · Benno Lossin
Quoted 28 lines · Alice Ryhl
Quoted 21 lines · Benno Lossin
Quoted 15 lines · Alice Ryhl

rust/pin-init/src/macros.rs fn drop(&mut self) { · line 1006

Quoted 13 lines · Benno Lossin
rust/pin-init/src/macros.rs +13 -0
+    (make_pin_projections:
+        @vis($vis:vis),
+        @name($name:ident),
+        @impl_generics($($impl_generics:tt)*),
+        @ty_generics($($ty_generics:tt)*),
+        @decl_generics($($decl_generics:tt)*),
+        @where($($whr:tt)*),
+        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
+        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
+    ) => {
+        $crate::macros::paste! {
+            #[doc(hidden)]
+            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {
Quoted 3 lines

I'm not sure we want $vis here. That's the visibility of the original struct, but I don't think we want it to be pub just because the struct is.

Quoted 5 lines

Why shouldn't it be pub if the original is pub? I don't really understand the concern, since the fields themselves will still have the correct visibility. Additionally, there is the ___pin_phantom_data field that's always private, so you cannot construct this outside of the module.

Quoted 3 lines

I mean, for instance, it's going to mean that every single struct that wraps Opaque in a private field will get a useless pub function called project that will appear in html docs.

Quoted 7 lines

It's #[doc(hidden)] :)

Quoted 1 line

Pin-project limits the visibility to pub(crate) when the struct is pub.

I think I would have to look inside the vis to recreate that behavior, so I'd rather do it as a future patch. Thoughts?

This reminds me: I think should make these functions #[inline] for now? (Until we make a decision about whether it's pub(crate) or $vis)

Otherwise compiler will generate functions in kernel binaries for some of them. E.g.

nm .kunit/vmlinux.o | rustfilt | grep project
00000000002449cc T <kernel::sync::LockClassKey>::project
000000000023ef40 T <kernel::sync::completion::Completion>::project
000000000023ef40 T <kernel::sync::poll::PollCondVar>::project
0000000000244994 T <kernel::sync::condvar::CondVar>::project
0000000000260a68 T <doctests_kernel_generated::rust_doctest_kernel_init_rs_3::main::_doctest_main____rust_kernel_init_rs_69_0::RawFoo>::project 0000000000008b70 d __UNIQUE_ID___addressable__RNvMs0_NtCshc5sK6KjdJJ_6kernel4syncNtB5_12LockClassKey7project2007 0000000000008c98 d __UNIQUE_ID___addressable__RNvMs1_NtNtCshc5sK6KjdJJ_6kernel4sync10completionNtB5_10Completion7project2044 0000000000008ca0 d __UNIQUE_ID___addressable__RNvMs1_NtNtCshc5sK6KjdJJ_6kernel4sync4pollNtB5_11PollCondVar7project2045 0000000000008b60 d __UNIQUE_ID___addressable__RNvMs1_NtNtCshc5sK6KjdJJ_6kernel4sync7condvarNtB5_7CondVar7project2005 0000000000010d28 r __export_symbol_<kernel::sync::LockClassKey>::project
0000000000010f78 r __export_symbol_<kernel::sync::completion::Completion>::project
0000000000010f88 r __export_symbol_<kernel::sync::poll::PollCondVar>::project
0000000000010d08 r __export_symbol_<kernel::sync::condvar::CondVar>::project

Otherwise the patch looks good to me. Feel free to add:

Regards,
Boqun

Quoted 3 lines

---
Cheers,
Benno

maintainer Reviewed-by on v1 2/2
#11 lore raw

Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`

In reply to Benno Lossin
Quoted 10 lines · On Fri, 5 Sep 2025 19:12:07 +0200 Benno Lossin <[email protected]> wrote:

Make the #[pin_data] macro generate a *Projection struct that holds either Pin<&mut Field> or &mut Field for every field of the original struct. Which version is chosen depends on weather there is a #[pin] or not respectively. Access to this projected version is enabled through generating fn project(self: Pin<&mut Self>) -> SelfProjection<'_>.

[ Adapt workqueue to use the new projection instead of its own, custom
one - Benno ]

LGTM, make sure to remove the spurious comment that Alice mentioned.

Quoted 30 lines
---
 rust/kernel/workqueue.rs    | 10 ++-----
 rust/pin-init/src/macros.rs | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 8 deletions(-)
rust/kernel/workqueue.rs +2 -8
index b9343d5bc00f..6ca14c629643 100644
@@ -356,18 +356,12 @@ struct ClosureWork<T> {
     func: Option<T>,
 }
 
-impl<T> ClosureWork<T> {
-    fn project(self: Pin<&mut Self>) -> &mut Option<T> {
-        // SAFETY: The `func` field is not structurally pinned.
-        unsafe { &mut self.get_unchecked_mut().func }
-    }
-}
-
 impl<T: FnOnce()> WorkItem for ClosureWork<T> {
     type Pointer = Pin<KBox<Self>>;
 
     fn run(mut this: Pin<KBox<Self>>) {
-        if let Some(func) = this.as_mut().project().take() {
+        if let Some(func) = this.as_mut().project().func.take() {
+            // if let Some(func) = this.as_mut().project_func().take() {
             (func)()
         }
     }