Re: [PATCH v2] rust: add procedural macro for declaring configfs attributes

From: Gary Guo

Date: Wed Jun 10 2026 - 06:05:38 EST


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