[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251222115956.62c7a4e5.gary@garyguo.net>
Date: Mon, 22 Dec 2025 11:59:56 +0000
From: Gary Guo <gary@...yguo.net>
To: "Benno Lossin" <lossin@...nel.org>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, "Danilo Krummrich" <dakr@...nel.org>,
"Fiona Behrens" <me@...enk.dev>, "Guilherme Giacomo Simoes"
<trintaeoitogc@...il.com>, José Expósito
<jose.exposito89@...il.com>, "Tamir Duberstein" <tamird@...il.com>,
<rust-for-linux@...r.kernel.org>, "David Gow" <davidgow@...gle.com>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 07/11] rust: macros: convert `concat_idents!` to use
`syn`
On Mon, 22 Dec 2025 07:34:24 +0100
"Benno Lossin" <lossin@...nel.org> wrote:
> On Thu Dec 11, 2025 at 7:56 PM CET, Gary Guo wrote:
> > From: Gary Guo <gary@...yguo.net>
> >
> > This eliminates the need for `expect_punct` helper.
>
> This commit message could use some more details :)
>
> > Signed-off-by: Gary Guo <gary@...yguo.net>
>
> Reviewed-by: Benno Lossin <lossin@...nel.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.
All our use cases have a prefix concatenated to a changing identifier,
hence the existing implementation use b's span.
Best,
Gary
>
> Cheers,
> Benno
>
> > TokenStream::from_iter([TokenTree::Ident(res)])
> > }
Powered by blists - more mailing lists