Re: [PATCH v2] rust: macros: update 'paste!' macro to accept string literals

From: Miguel Ojeda
Date: Wed Dec 13 2023 - 13:44:40 EST


On Sat, Nov 18, 2023 at 2:43 AM Trevor Gross <tmgross@xxxxxxxxx> wrote:
>
> Enable combining identifiers with literals in the 'paste!' macro. This
> allows combining user-specified strings with affixes to create
> namespaced identifiers.
>
> This sample code:
>
> macro_rules! m {
> ($name:lit) => {
> paste!(struct [<_some_ $name _struct_>] {})
> }
> }
>
> m!("foo_bar");
>
> Would previously cause a compilation error. It will now generate:
>
> struct _some_foo_bar_struct_ {}
>
> Signed-off-by: Trevor Gross <tmgross@xxxxxxxxx>
> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@xxxxxxxxx>
> Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@xxxxxxxxx>
> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>
> Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>

Applied to `rust-next` (with an added `:` before the example since
that is our usual convention).

Thanks everyone!

Cheers,
Miguel