Re: [PATCH] rust: add procedural macro for declaring configfs attributes
From: Gary Guo
Date: Thu May 21 2026 - 01:50:14 EST
On Wed May 20, 2026 at 9:40 AM CEST, Malte Wechter wrote:
> Implement `configfs_attrs!` as a procedural macro using `syn`, this
> improves readability and maintainability. Remove the old macro and
> replace all uses with the new macro. Add the new macro implementation
> file to MAINTAINERS.
The current declarative macro implementation is quite readable and IMO more so
than this syn rewrite.
Unless there's a compelling use case where it needs to be implememented using
token munchers with declarative macro but can be easily parsed with proc macro,
I think it should just stay as decl macro.
>
> Signed-off-by: Malte Wechter <maltewechter@xxxxxxxxx>
> ---
> MAINTAINERS | 1 +
> drivers/block/rnull/configfs.rs | 2 +-
> rust/kernel/configfs.rs | 251 ----------------------------------------
> rust/macros/configfs_attrs.rs | 182 +++++++++++++++++++++++++++++
> rust/macros/lib.rs | 85 ++++++++++++++
> samples/rust/rust_configfs.rs | 2 +-
> 6 files changed, 270 insertions(+), 253 deletions(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2fb1c75afd163..45f7a1ec93b45 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -6464,6 +6464,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/a.hindborg/linux.git config
> F: fs/configfs/
> F: include/linux/configfs.h
> F: rust/kernel/configfs.rs
> +F: rust/macros/configfs_attrs.rs
> F: samples/configfs/
> F: samples/rust/rust_configfs.rs
>
> diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs.rs
> index 7c2eb5c0b7228..f28ec69d79846 100644
> --- a/drivers/block/rnull/configfs.rs
> +++ b/drivers/block/rnull/configfs.rs
> @@ -4,8 +4,8 @@
> use kernel::{
> block::mq::gen_disk::{GenDisk, GenDiskBuilder},
> configfs::{self, AttributeOperations},
> - configfs_attrs,
> fmt::{self, Write as _},
> + macros::configfs_attrs,
Except for very generics things like `paste` or `concat_idents`, other things
should not live in kernel::macros (or from top-level) but be re-exported from
subsystems.
Best,
Gary
> new_mutex,
> page::PAGE_SIZE,
> prelude::*,
> diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs