The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] rust: macros: Allow omitting trailing commas in module!
@ 2026-08-06 10:14 Ethan Plant
  2026-08-06 11:54 ` Gary Guo
  0 siblings, 1 reply; 3+ messages in thread
From: Ethan Plant @ 2026-08-06 10:14 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Luis Chamberlain, Petr Pavlu,
	Daniel Gomez, Sami Tolvanen, Aaron Tomlin
  Cc: rust-for-linux, linux-kernel, linux-modules, Ethan Plant

The module! macro currently requires a trailing comma after the final
argument, despite using syntax modeled on Rust struct initializers,
where trailing commas are optional.

Allow parsing to finish after the final field when the input stream is
empty. If more input remains, continue requiring a comma, so missing
separators between fields are still rejected.

Document that the final trailing comma is optional and update an existing
module! doctest to exercise the syntax without one.

Suggested-by: Benno Lossin <lossin@kernel.org>
Link: https://github.com/Rust-for-Linux/linux/issues/1172
Signed-off-by: Ethan Plant <plant.ethan@gmail.com>
---
 rust/macros/lib.rs    | 4 +++-
 rust/macros/module.rs | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index 4a48fabbc2682..f6474b194687f 100644
--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -61,6 +61,8 @@
 ///
 /// [`Module`]: ../kernel/trait.Module.html
 ///
+/// The trailing comma after the final field is optional.
+///
 /// # Examples
 ///
 /// ```ignore
@@ -112,7 +114,7 @@
 ///     authors: ["Rust for Linux Contributors"],
 ///     description: "My device driver requires firmware",
 ///     license: "GPL",
-///     firmware: ["my_device_firmware1.bin", "my_device_firmware2.bin"],
+///     firmware: ["my_device_firmware1.bin", "my_device_firmware2.bin"]
 /// }
 ///
 /// struct MyDeviceDriverModule;
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 06c18e2075083..57ee79b49a7ec 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -261,8 +261,13 @@ macro_rules! parse_ordered_fields {
                 }
             }
 
-            $input.parse::<Token![,]>()?;
             seen_keys.push(key);
+
+            if $input.is_empty() {
+                break;
+            }
+
+            $input.parse::<Token![,]>()?;
         }
 
         for key in REQUIRED_KEYS {

---
base-commit: dc01dfb37b34beeefcfe1c3055364d41a4070c7e
change-id: 20260806-module-optional-trailing-comma-44a336ddf649

Best regards,
--  
Ethan Plant <plant.ethan@gmail.com>


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

end of thread, other threads:[~2026-08-06 12:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 10:14 [PATCH] rust: macros: Allow omitting trailing commas in module! Ethan Plant
2026-08-06 11:54 ` Gary Guo
2026-08-06 12:08   ` Miguel Ojeda

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