Re: [PATCH v1 05/28] rust: macros: add `concat_idents!` proc macro

From: Björn Roy Baron
Date: Mon Nov 14 2022 - 09:40:19 EST


On Monday, November 14th, 2022 at 15:26, Gary Guo <gary@xxxxxxxxxxx> wrote:


> On Thu, 10 Nov 2022 17:41:17 +0100
> Miguel Ojeda ojeda@xxxxxxxxxx wrote:
>
> > +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");
> > + let res = Ident::new(&(a.to_string() + &b.to_string()), b.span());
>
>
> Probably clearer to write `Ident::new(&format!("{a}{b}"), b.span())`
> here?
>
> Best,
> Gary

I agree that is clearer. I hadn't considered that Ident implements Display when I wrote it.

Cheers,
Björn