From: Gary Guo <gary@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org
Subject: [PATCH v3 00/12] refactor Rust proc macros with `syn`
Date: Mon, 12 Jan 2026 17:07:11 +0000 [thread overview]
Message-ID: <20260112170919.1888584-1-gary@kernel.org> (raw)
From: Gary Guo <gary@garyguo.net>
This series convert Rust proc macros that we have with `syn`, and replace the
custom `quote!` macro that we have with the vendored `quote!` macro. The
`pin-init` macros are not converted `syn` yet; Benno has a work in progress in
converting them. They're however converted to use `quote` and `proc-macro2`
crate so our custom `quote!` macro can be removed.
Overall this improves the robustness of the macros as we have precise parsing of
the AST rather than relying on heuristics to extract needed information from
there. This is also a quality-of-life improvement to those using language
servers (e.g. Rust analyzer) as the span information of the proc macros are now
preserved which allows the "jump-to-definition" feature to work, even when used
on completely custom macros such as `module!`.
Miguel gave a very good explaination on why `syn` is a good idea in the patch
series that introduced it [1], which I shall not repeat here.
Link: https://lore.kernel.org/rust-for-linux/20251124151837.2184382-1-ojeda@kernel.org/ [1]
Changes since v2:
- Changes are limited to `#[vtable]` and `module!` macros.
- `#[vtable]` macro is reworked per Tamir's suggestion. This makes it easy
to support `#[cfg]` properly, and hence a new patch is added to do that.
- Avoided variable renames related to `param_name`/`param_type` between
patches in `module!` macro
- `CString` is now interpolated directly without adding extra
`Literal::c_string`.
- Fixed an typo that affects only `CONFIG_HAVE_ARCH_PREL32_RELOCATIONS`
builds.
- Link to v2: https://lore.kernel.org/rust-for-linux/20260107161729.3855851-1-gary@kernel.org/
Changes since v1:
- Fixed clippy warnings when moving from `proc-macro` to `proc-macro2`
(extra trait impl in `proc-macro2` causes some `.to_string()` to be
unnecessary).
- A Makefile change to pin-init-internal that is mistakenly included in
patch 5/11 is moved to the correct patch 1/11.
- `module!` parsing has been completely reworked to support `imports_ns`
and `params`. As there're two structs that need to parse ordered fields
(`ModuleInfo` and `Parameter`), a `parse_ordered_field` macro is added
and it is used to implement the parsing instead of `ModInfoField` and
custom keywords.
- Link to v1: https://lore.kernel.org/rust-for-linux/20251211185805.2835633-1-gary@kernel.org/
Benno Lossin (1):
rust: pin-init: internal: remove proc-macro[2] and quote workarounds
Gary Guo (11):
rust: macros: use `quote!` from vendored crate
rust: macros: convert `#[vtable]` macro to use `syn`
rust: macros: use `syn` to parse `module!` macro
rust: macros: use `quote!` for `module!` macro
rust: macros: convert `#[export]` to use `syn`
rust: macros: convert `concat_idents!` to use `syn`
rust: macros: convert `#[kunit_tests]` macro to use `syn`
rust: macros: allow arbitrary types to be used in `module!` macro
rust: macros: rearrange `#[doc(hidden)]` in `module!` macro
rust: kunit: use `pin_init::zeroed` instead of custom null value
rust: macros: support `#[cfg]` properly in `#[vtable]` macro.
rust/Makefile | 16 +-
rust/kernel/kunit.rs | 26 +-
rust/macros/concat_idents.rs | 39 +-
rust/macros/export.rs | 26 +-
rust/macros/fmt.rs | 4 +-
rust/macros/helpers.rs | 130 +---
rust/macros/kunit.rs | 275 +++----
rust/macros/lib.rs | 41 +-
rust/macros/module.rs | 907 ++++++++++++----------
rust/macros/paste.rs | 2 +-
rust/macros/quote.rs | 182 -----
rust/macros/vtable.rs | 165 ++--
rust/pin-init/internal/src/helpers.rs | 7 +-
rust/pin-init/internal/src/lib.rs | 16 -
rust/pin-init/internal/src/pin_data.rs | 18 +-
rust/pin-init/internal/src/pinned_drop.rs | 10 +-
rust/pin-init/internal/src/zeroable.rs | 6 +-
scripts/generate_rust_analyzer.py | 2 +-
18 files changed, 842 insertions(+), 1030 deletions(-)
delete mode 100644 rust/macros/quote.rs
base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb
--
2.51.2
next reply other threads:[~2026-01-12 17:10 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-12 17:07 Gary Guo [this message]
2026-01-12 17:07 ` [PATCH v3 01/12] rust: pin-init: internal: remove proc-macro[2] and quote workarounds Gary Guo
2026-01-12 17:07 ` [PATCH v3 02/12] rust: macros: use `quote!` from vendored crate Gary Guo
2026-01-19 7:09 ` David Gow
2026-01-12 17:07 ` [PATCH v3 03/12] rust: macros: convert `#[vtable]` macro to use `syn` Gary Guo
2026-01-17 19:25 ` Benno Lossin
2026-01-12 17:07 ` [PATCH v3 04/12] rust: macros: use `syn` to parse `module!` macro Gary Guo
2026-01-17 20:12 ` Benno Lossin
2026-01-12 17:07 ` [PATCH v3 05/12] rust: macros: use `quote!` for " Gary Guo
2026-01-12 17:07 ` [PATCH v3 06/12] rust: macros: convert `#[export]` to use `syn` Gary Guo
2026-01-12 17:07 ` [PATCH v3 07/12] rust: macros: convert `concat_idents!` " Gary Guo
2026-01-12 17:07 ` [PATCH v3 08/12] rust: macros: convert `#[kunit_tests]` macro " Gary Guo
2026-01-17 20:09 ` Benno Lossin
2026-01-19 7:10 ` David Gow
2026-01-12 17:07 ` [PATCH v3 09/12] rust: macros: allow arbitrary types to be used in `module!` macro Gary Guo
2026-01-12 17:07 ` [PATCH v3 10/12] rust: macros: rearrange `#[doc(hidden)]` " Gary Guo
2026-01-12 17:07 ` [PATCH v3 11/12] rust: kunit: use `pin_init::zeroed` instead of custom null value Gary Guo
2026-01-19 7:10 ` David Gow
2026-01-12 17:07 ` [PATCH v3 12/12] rust: macros: support `#[cfg]` properly in `#[vtable]` macro Gary Guo
2026-01-12 17:48 ` Tamir Duberstein
2026-01-13 13:11 ` [PATCH] " Gary Guo
2026-01-13 13:39 ` Tamir Duberstein
2026-01-13 14:09 ` Gary Guo
2026-01-13 14:23 ` Tamir Duberstein
2026-01-13 17:05 ` [PATCH v2] " Gary Guo
2026-01-17 20:09 ` Benno Lossin
2026-01-28 15:09 ` [PATCH v3 00/12] refactor Rust proc macros with `syn` Miguel Ojeda
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=20260112170919.1888584-1-gary@kernel.org \
--to=gary@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--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