public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/11] refactor Rust proc macros with `syn`
@ 2026-01-07 16:15 Gary Guo
  2026-01-07 16:15 ` [PATCH v2 01/11] rust: pin-init: internal: remove proc-macro[2] and quote workarounds Gary Guo
                   ` (10 more replies)
  0 siblings, 11 replies; 23+ messages in thread
From: Gary Guo @ 2026-01-07 16:15 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich
  Cc: rust-for-linux

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 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 (10):
  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/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                    | 129 +---
 rust/macros/kunit.rs                      | 275 +++----
 rust/macros/lib.rs                        |  41 +-
 rust/macros/module.rs                     | 902 ++++++++++++----------
 rust/macros/paste.rs                      |   2 +-
 rust/macros/quote.rs                      | 182 -----
 rust/macros/vtable.rs                     | 164 ++--
 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, 833 insertions(+), 1032 deletions(-)
 delete mode 100644 rust/macros/quote.rs


base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb
-- 
2.51.2


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2026-01-11 21:25 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-07 16:15 [PATCH v2 00/11] refactor Rust proc macros with `syn` Gary Guo
2026-01-07 16:15 ` [PATCH v2 01/11] rust: pin-init: internal: remove proc-macro[2] and quote workarounds Gary Guo
2026-01-07 16:40   ` Tamir Duberstein
2026-01-07 16:15 ` [PATCH v2 02/11] rust: macros: use `quote!` from vendored crate Gary Guo
2026-01-07 16:15 ` [PATCH v2 03/11] rust: macros: convert `#[vtable]` macro to use `syn` Gary Guo
2026-01-07 16:48   ` Tamir Duberstein
2026-01-08 12:41     ` Gary Guo
2026-01-08 15:10       ` Tamir Duberstein
2026-01-08 15:24         ` Gary Guo
2026-01-11 17:03   ` Benno Lossin
2026-01-11 21:25     ` Gary Guo
2026-01-07 16:15 ` [PATCH v2 04/11] rust: macros: use `syn` to parse `module!` macro Gary Guo
2026-01-07 17:11   ` Tamir Duberstein
2026-01-07 16:15 ` [PATCH v2 05/11] rust: macros: use `quote!` for " Gary Guo
2026-01-07 17:19   ` Tamir Duberstein
2026-01-07 17:54     ` Gary Guo
2026-01-07 16:15 ` [PATCH v2 06/11] rust: macros: convert `#[export]` to use `syn` Gary Guo
2026-01-07 16:15 ` [PATCH v2 07/11] rust: macros: convert `concat_idents!` " Gary Guo
2026-01-07 16:15 ` [PATCH v2 08/11] rust: macros: convert `#[kunit_tests]` macro " Gary Guo
2026-01-07 17:22   ` Tamir Duberstein
2026-01-07 16:15 ` [PATCH v2 09/11] rust: macros: allow arbitrary types to be used in `module!` macro Gary Guo
2026-01-07 16:15 ` [PATCH v2 10/11] rust: macros: rearrange `#[doc(hidden)]` " Gary Guo
2026-01-07 16:15 ` [PATCH v2 11/11] rust: kunit: use `pin_init::zeroed` instead of custom null value Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox