From: Malte Wechter <maltewechter@gmail.com>
To: "Gary Guo" <gary@garyguo.net>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Breno Leitao" <leitao@debian.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Jens Axboe" <axboe@kernel.dk>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-block@vger.kernel.org
Subject: Re: [PATCH v2] rust: add procedural macro for declaring configfs attributes
Date: Wed, 10 Jun 2026 16:48:16 +0200 [thread overview]
Message-ID: <9627f522-7d94-48c8-9848-30761c9234bd@gmail.com> (raw)
In-Reply-To: <DJ5A9HIJ43EJ.2K3SCFI7UR3NF@garyguo.net>
On 6/10/26 12:05 PM, Gary Guo wrote:
> On Wed Jun 10, 2026 at 10:15 AM BST, Malte Wechter wrote:
>>>> +
>>>> + Ok(ConfigfsAttrs {
>>>> + container,
>>>> + data,
>>>> + child,
>>>> + attributes,
>>>> + })
>>>> + }
>>>> +}
>>>> +
>>>> +fn make_static_ident<T: ToTokens>(ty: &T, suffix: &str) -> syn::Ident {
>>>> + let raw_id = quote! { #ty }.to_string();
>>>> +
>>>> + // Sanitizing syn::Type::Path, this is safe since it is
>>>> + // only used as the identifier.
>>>> + let normalized = raw_id
>>>> + .split("::")
>>>> + .map(|s| String::from(s.trim()))
>>>> + .reduce(|a, b| format!("{a}_{b}"))
>>>> + .expect("Cannot be empty")
>>>> + .to_uppercase()
>>>> + .replace(|c: char| !c.is_alphanumeric(), "_");
>>>> +
>>>> + Ident::new(&format!("{}_{}", normalized, suffix), ty.span())
>>>> +}
>>>> +
>>>> +pub(crate) fn configfs_attrs(cfs_attrs: ConfigfsAttrs) -> proc_macro2::TokenStream {
>>>> + let (container_ty, data_ty) = (&cfs_attrs.container, &cfs_attrs.data);
>>>> +
>>>> + let data_tp_ident = make_static_ident(data_ty, "TPE");
>>>> + let data_attr_ident = make_static_ident(data_ty, "ATTR_LIST");
>>> Instead of creating identifers like this, just scope them properly so that
>>> a fixed identifier is used without colliding.
>> I believe it is nice to keep the identifiers unique, especially if you
>> have many fields
>> you can easily differentiate them.
> What make_static_ident is doing I think is quite hacky. I'd rather not having
> them. Plus, the identifiers are not seen by users anyway.
>
> Best,
> Gary
I will simplify the naming of the static variables greatly (removing
make_static_ident), but still generate unique identifiers.
Best regards,
Malte
prev parent reply other threads:[~2026-06-10 14:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 14:08 [PATCH v2] rust: add procedural macro for declaring configfs attributes Malte Wechter
2026-06-03 14:32 ` Gary Guo
2026-06-10 9:15 ` Malte Wechter
2026-06-10 10:05 ` Gary Guo
2026-06-10 14:48 ` Malte Wechter [this message]
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=9627f522-7d94-48c8-9848-30761c9234bd@gmail.com \
--to=maltewechter@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=axboe@kernel.dk \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=leitao@debian.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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