From: Jack Whitehorn <jackwh.whitehorn@gmail.com>
To: ojeda@kernel.org
Cc: aliceryhl@google.com, rust-for-linux@vger.kernel.org,
Jack Whitehorn <jackwh.whitehorn@gmail.com>
Subject: [PATCH] rust: add support for trailing comma in fmt! macros with named format arguments
Date: Fri, 6 Mar 2026 17:40:29 +0000 [thread overview]
Message-ID: <20260306174126.76296-1-jackwh.whitehorn@gmail.com> (raw)
Fixes an issue with fmt! and similar macros where the combination of a
trailing comma and one or more named format arguments would cause the
macro to fail.
Tested using a modified rust_minimal module, and checked that the rust
samples and some rust drivers still compile.
Signed-off-by: Jack Whitehorn <jackwh.whitehorn@gmail.com>
Suggested-by: Alice Rhyl <aliceryhl@google.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1227
---
rust/macros/fmt.rs | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/rust/macros/fmt.rs b/rust/macros/fmt.rs
index ce6c7249305a..a1d64c0d85fe 100644
--- a/rust/macros/fmt.rs
+++ b/rust/macros/fmt.rs
@@ -50,6 +50,7 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream {
let adapter = quote_spanned!(first_span => ::kernel::fmt::Adapter);
let mut args = TokenStream::from_iter(first_opt);
+
{
let mut flush = |args: &mut TokenStream, current: &mut TokenStream| {
let current = std::mem::take(current);
@@ -69,7 +70,7 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream {
}
(None, acc)
})();
- args.extend(quote_spanned!(first_span => #lhs #adapter(&(#rhs))));
+ args.extend(quote_spanned!(first_span => , #lhs #adapter(&(#rhs))));
}
};
@@ -78,11 +79,9 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream {
match &tt {
TokenTree::Punct(p) if p.as_char() == ',' => {
flush(&mut args, &mut current);
- &mut args
}
- _ => &mut current,
- }
- .extend([tt]);
+ _ => current.extend([tt]),
+ };
}
flush(&mut args, &mut current);
}
--
2.53.0
reply other threads:[~2026-03-06 17:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260306174126.76296-1-jackwh.whitehorn@gmail.com \
--to=jackwh.whitehorn@gmail.com \
--cc=aliceryhl@google.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/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