linux/rust/kernel/io
Gary Guo 63b2578517 rust: io: register: reimplement as proc macro
The existing `register!` macro is implemented as a declarative macro.
Reimplement it as proc macro instead, with no functional changes intended.

The old implementation produces unhelpful diagnostics when things go wrong.
For example, for code like

    register! {
        pub(crate) TESTREG(u32) {
            31:0    data;
        }
    }

which misses out the "@ offset" part of the specification, and the
following error is produced:

error: no rules expected `{`
   --> test.rs:42:5
    |
 42 | /     register! {
 43 | |         pub(crate) TESTREG(u32) {
 44 | |             31:0    data;
...   |
100 | |     }
    | |_____^ no rules expected this token in macro call

which isn't very helpful. With the proc macro implementation, the following
error is produced:

error: expected `@` or `=>`
  --> tests.rs:43:33
   |
43 |         pub(crate) TESTREG(u32) {
   |                                 ^

which is much more helpful. Apart from diagnostics, proc macro also has a
benefit of not having follow-set restrictions, which makes syntax like

    register!(name: ty @ offset);

possible; declarative macro will reject this as `@` is not in the
follow-set of "ty" metavariable kind.

Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20260901-typed_register-v4-1-5552b1d59525@garyguo.net
[ Fix typo in module-level doc comment and fix ArrayDef syntax
  description to match the actual macro syntax. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2026-09-03 20:25:54 +02:00
..
mem.rs I/O type generalization and projection 2026-07-13 23:50:39 +02:00
poll.rs rust: io: implement Mmio as view type 2026-07-11 17:59:32 +02:00
register.rs rust: io: register: reimplement as proc macro 2026-09-03 20:25:54 +02:00
resource.rs rust: make build_assert module the home of related macros 2026-06-10 09:07:13 +02:00