]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: macros: use `syn` to parse `module!` macro
authorGary Guo <gary@garyguo.net>
Mon, 12 Jan 2026 17:07:15 +0000 (17:07 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 27 Jan 2026 23:55:24 +0000 (00:55 +0100)
commitc578ad703ae9a219aa4bdd13343cf5254541c5e3
tree1b2ce44e85640bb951d914a34ebc37cad6261130
parent5f160950a5cdc36f222299905e09a72f67ebfcd4
rust: macros: use `syn` to parse `module!` macro

With `syn` being available in the kernel, use it to parse the complex
custom `module!` macro to replace existing helpers. Only parsing is
changed in this commit, the code generation is untouched.

This has the benefit of better error message when the macro is used
incorrectly, as it can point to a concrete span on what's going wrong.

For example, if a field is specified twice, previously it reads:

    error: proc macro panicked
      --> samples/rust/rust_minimal.rs:7:1
       |
    7  | / module! {
    8  | |     type: RustMinimal,
    9  | |     name: "rust_minimal",
    10 | |     author: "Rust for Linux Contributors",
    11 | |     description: "Rust minimal sample",
    12 | |     license: "GPL",
    13 | |     license: "GPL",
    14 | | }
       | |_^
       |
       = help: message: Duplicated key "license". Keys can only be specified once.

now it reads:

    error: duplicated key "license". Keys can only be specified once.
      --> samples/rust/rust_minimal.rs:13:5
       |
    13 |     license: "GPL",
       |     ^^^^^^^

Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://patch.msgid.link/20260112170919.1888584-5-gary@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/macros/helpers.rs
rust/macros/lib.rs
rust/macros/module.rs