mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Malte Wechter" <maltewechter@gmail.com>,
	"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 11:05:14 +0100	[thread overview]
Message-ID: <DJ5A9HIJ43EJ.2K3SCFI7UR3NF@garyguo.net> (raw)
In-Reply-To: <f6a513e8-227f-4b22-bd4d-81d88536eff1@gmail.com>

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

  reply	other threads:[~2026-06-10 10:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 14:08 Malte Wechter
2026-06-03 14:32 ` Gary Guo
2026-06-10  9:15   ` Malte Wechter
2026-06-10 10:05     ` Gary Guo [this message]
2026-06-10 14:48       ` Malte Wechter

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=DJ5A9HIJ43EJ.2K3SCFI7UR3NF@garyguo.net \
    --to=gary@garyguo.net \
    --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=leitao@debian.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=maltewechter@gmail.com \
    --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

all inboxes | Powered by JetHome®