Re: [PATCH 07/11] rust: macros: convert `concat_idents!` to use `syn`

Benno Lossin
2025-12-22T06:34:29Z

On Thu Dec 11, 2025 at 7:56 PM CET, Gary Guo wrote:
> From: Gary Guo <gary@garyguo.net>
>
> This eliminates the need for `expect_punct` helper.

This commit message could use some more details :)

> Signed-off-by: Gary Guo <gary@garyguo.net>

Reviewed-by: Benno Lossin <lossin@kernel.org>

> ---
> rust/macros/concat_idents.rs | 39 ++++++++++++++++++++++++------------
> rust/macros/helpers.rs | 14 +------------
> rust/macros/lib.rs | 4 ++--
> 3 files changed, 29 insertions(+), 28 deletions(-)

> -pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
> - let mut it = ts.into_iter();
> - let a = expect_ident(&mut it);
> - assert_eq!(expect_punct(&mut it), ',');
> - let b = expect_ident(&mut it);
> - assert!(it.next().is_none(), "only two idents can be concatenated");
> +pub(crate) fn concat_idents(Input { a, b, .. }: Input) -> TokenStream {
> let res = Ident::new(&format!("{a}{b}"), b.span());

There is `quote::format_ident!`, which directly returns an identifier,
but with the span of the first of the two. Not sure if that is better.

Cheers,
Benno

> TokenStream::from_iter([TokenTree::Ident(res)])
> }