From: "Gary Guo" <gary@garyguo.net>
To: "Ethan Plant" <plant.ethan@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "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>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Petr Pavlu" <petr.pavlu@suse.com>,
"Daniel Gomez" <da.gomez@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
"Aaron Tomlin" <atomlin@atomlin.com>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-modules@vger.kernel.org>
Subject: Re: [PATCH] rust: macros: Allow omitting trailing commas in module!
Date: Thu, 06 Aug 2026 12:54:15 +0100 [thread overview]
Message-ID: <DKHUA0DRQXYP.1WH8F0FP7N39L@garyguo.net> (raw)
In-Reply-To: <20260806-module-optional-trailing-comma-v1-1-d04811335e59@gmail.com>
On Thu Aug 6, 2026 at 11:14 AM BST, Ethan Plant wrote:
> 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.
Hmm, I am not sure if we really want this.
`module!` invocation usually spans multiple lines so the formatting rules would
always prefer adding trailing comma for this case.
Allowing omitting sounds like encouraging bad practice.
Best,
Gary
>
> 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>
next prev parent reply other threads:[~2026-08-06 11:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 10:14 [PATCH] rust: macros: Allow omitting trailing commas in module! Ethan Plant
2026-08-06 11:54 ` Gary Guo [this message]
2026-08-06 12:08 ` 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=DKHUA0DRQXYP.1WH8F0FP7N39L@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=atomlin@atomlin.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=da.gomez@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mcgrof@kernel.org \
--cc=ojeda@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=plant.ethan@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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