rust: add support for trailing comma in fmt! macros with named format arguments
PATCH 1/1 rust: add support for trailing comma in fmt! macros with named format arguments
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 <[email protected]>
Suggested-by Alice Rhyl <[email protected]>
--- rust/macros/fmt.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
rust/macros/fmt.rs +4 -5
@@ -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); }
Signature · 1 line
2.53.0