public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: add support for trailing comma in fmt! macros with named format arguments
@ 2026-03-06 17:40 Jack Whitehorn
  0 siblings, 0 replies; only message in thread
From: Jack Whitehorn @ 2026-03-06 17:40 UTC (permalink / raw)
  To: ojeda; +Cc: aliceryhl, rust-for-linux, Jack Whitehorn

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-03-06 17:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 17:40 [PATCH] rust: add support for trailing comma in fmt! macros with named format arguments Jack Whitehorn

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