Re: [PATCH 07/11] rust: macros: convert `concat_idents!` to use `syn`
From: Benno Lossin
Date: Mon Dec 22 2025 - 01:34:29 EST
On Thu Dec 11, 2025 at 7:56 PM CET, Gary Guo wrote:
> From: Gary Guo <gary@xxxxxxxxxxx>
>
> This eliminates the need for `expect_punct` helper.
This commit message could use some more details :)
> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
Reviewed-by: Benno Lossin <lossin@xxxxxxxxxx>
> ---
> 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)])
> }