[PATCH 6/8] rust: pin-init: internal: pin_data: extract `#[cfg]` processing to its own function
From: Gary Guo
Date: Tue Oct 06 2026 - 11:36:27 EST
The `pin_data` function is getting big. Split the `#[cfg]` handling which
does not interact with other part of expansion to its own `expand_with_cfg`
function.
Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
---
rust/pin-init/internal/src/lib.rs | 3 ++-
rust/pin-init/internal/src/pin_data.rs | 13 +++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/rust/pin-init/internal/src/lib.rs b/rust/pin-init/internal/src/lib.rs
index 07b3d33d2282..01e19fcd31fb 100644
--- a/rust/pin-init/internal/src/lib.rs
+++ b/rust/pin-init/internal/src/lib.rs
@@ -22,7 +22,8 @@
#[proc_macro_attribute]
pub fn pin_data(args: TokenStream, input: TokenStream) -> TokenStream {
- DiagCtxt::for_item(|dcx| pin_data::pin_data(syn::parse(args)?, syn::parse(input)?, dcx)).into()
+ DiagCtxt::for_item(|dcx| pin_data::expand_with_cfg(syn::parse(args)?, syn::parse(input)?, dcx))
+ .into()
}
#[proc_macro_attribute]
diff --git a/rust/pin-init/internal/src/pin_data.rs b/rust/pin-init/internal/src/pin_data.rs
index 3acced1fe806..a4d6965c1572 100644
--- a/rust/pin-init/internal/src/pin_data.rs
+++ b/rust/pin-init/internal/src/pin_data.rs
@@ -8,7 +8,8 @@
punctuated::Punctuated,
spanned::Spanned,
visit_mut::VisitMut,
- Field, Fields, Generics, Ident, Index, Item, Member, PathSegment, Type, TypePath, Visibility,
+ Field, Fields, Generics, Ident, Index, Item, ItemStruct, Member, PathSegment, Type, TypePath,
+ Visibility,
};
use crate::{
@@ -54,7 +55,7 @@ struct FieldInfo<'a> {
pinned: bool,
}
-pub(crate) fn pin_data(
+pub(crate) fn expand_with_cfg(
args: Args,
input: Item,
dcx: &mut DiagCtxt,
@@ -120,6 +121,14 @@ pub(crate) fn pin_data(
));
}
+ expand(args, struct_, dcx)
+}
+
+fn expand(
+ args: Args,
+ mut struct_: ItemStruct,
+ dcx: &mut DiagCtxt,
+) -> Result<TokenStream, ErrorGuaranteed> {
// The generics might contain the `Self` type. Since this macro will define a new type with the
// same generics and bounds, this poses a problem: `Self` will refer to the new type as opposed
// to this struct definition. Therefore we have to replace `Self` with the concrete name.
--
2.54.0