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: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Gary Guo <gary@garyguo.net>
Subject: [PATCH 1/4] rust: pin-init: internal: extract utility code to new module
Date: Fri, 04 Sep 2026 15:12:29 +0100 [thread overview]
Message-ID: <20260904-tuple-struct-v1-1-72c50bd037fd@garyguo.net> (raw)
In-Reply-To: <20260904-tuple-struct-v1-0-72c50bd037fd@garyguo.net>
Create a new `util.rs` to host utility code that are generic and can be
shared by multiple macros.
Signed-off-by: Gary Guo <gary@garyguo.net>
---
rust/pin-init/internal/src/lib.rs | 1 +
rust/pin-init/internal/src/pin_data.rs | 17 +++++------------
rust/pin-init/internal/src/util.rs | 27 +++++++++++++++++++++++++++
3 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/rust/pin-init/internal/src/lib.rs b/rust/pin-init/internal/src/lib.rs
index 60d5093f3128..4d8ff86484b6 100644
--- a/rust/pin-init/internal/src/lib.rs
+++ b/rust/pin-init/internal/src/lib.rs
@@ -18,6 +18,7 @@
mod init;
mod pin_data;
mod pinned_drop;
+mod util;
mod zeroable;
#[proc_macro_attribute]
diff --git a/rust/pin-init/internal/src/pin_data.rs b/rust/pin-init/internal/src/pin_data.rs
index ff194d27565e..074bc6b3091a 100644
--- a/rust/pin-init/internal/src/pin_data.rs
+++ b/rust/pin-init/internal/src/pin_data.rs
@@ -10,7 +10,10 @@
Field, Fields, Generics, Ident, Item, PathSegment, Type, TypePath, Visibility, WhereClause,
};
-use crate::diagnostics::{DiagCtxt, ErrorGuaranteed};
+use crate::{
+ diagnostics::{DiagCtxt, ErrorGuaranteed},
+ util::*,
+};
pub(crate) mod kw {
syn::custom_keyword!(PinnedDrop);
@@ -81,21 +84,11 @@ pub(crate) fn pin_data(
//
// We need to perform this after parsing so we can reliably detect field cfgs.
for (field_idx, field) in struct_.fields.iter_mut().enumerate() {
- let cfg: Vec<_> = field
- .attrs
- .iter()
- .filter(|a| a.path().is_ident("cfg"))
- .map(|a| {
- a.parse_args::<TokenStream>()
- .expect("parse as token stream cannot fail")
- })
- .collect();
-
+ let cfg = field.attrs.extract_cfg_attrs();
if cfg.is_empty() {
continue;
}
- field.attrs.retain(|a| !a.path().is_ident("cfg"));
let cfg_true_struct = quote!(#struct_);
let punctuated = match &mut struct_.fields {
diff --git a/rust/pin-init/internal/src/util.rs b/rust/pin-init/internal/src/util.rs
new file mode 100644
index 000000000000..ed18ab7d45e6
--- /dev/null
+++ b/rust/pin-init/internal/src/util.rs
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: Apache-2.0 OR MIT
+
+use proc_macro2::TokenStream;
+use syn::Attribute;
+
+pub(crate) trait AttrListExt {
+ fn extract_cfg_attrs(&mut self) -> Vec<TokenStream>;
+}
+
+impl AttrListExt for Vec<Attribute> {
+ fn extract_cfg_attrs(&mut self) -> Vec<TokenStream> {
+ let cfg: Vec<_> = self
+ .iter()
+ .filter(|a| a.path().is_ident("cfg"))
+ .map(|a| {
+ a.parse_args::<TokenStream>()
+ .expect("parse as token stream cannot fail")
+ })
+ .collect();
+
+ if !cfg.is_empty() {
+ self.retain(|a| !a.path().is_ident("cfg"));
+ }
+
+ cfg
+ }
+}
--
2.54.0
next prev parent reply other threads:[~2026-09-04 14:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 14:12 [PATCH 0/4] rust: pin-init: support tuple structs Gary Guo
2026-09-04 14:12 ` Gary Guo [this message]
2026-09-04 14:12 ` [PATCH 2/4] rust: pin-init: internal: pin_data: support tuple struct projections Gary Guo
2026-09-04 14:12 ` [PATCH 3/4] rust: pin-init: internal: init: support tuple structs in `[pin_]init!` Gary Guo
2026-09-04 14:12 ` [PATCH 4/4] rust: pin-init: internal: init: support tuple struct constructor syntax 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=20260904-tuple-struct-v1-1-72c50bd037fd@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®