rust: macros: update 'paste!' macro to accept string literals
authorTrevor Gross <tmgross@umich.edu>
Sat, 18 Nov 2023 01:39:59 +0000 (20:39 -0500)
committerMiguel Ojeda <ojeda@kernel.org>
Thu, 14 Dec 2023 19:14:01 +0000 (20:14 +0100)
commit2dc318ea9681c14c37bad2715097df4380a3c547
tree08e7100ead1979309465902f09c227c0e736f5f2
parent743766565dc0bdeedf7db419500031c7bdc84033
rust: macros: update 'paste!' macro to accept string literals

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@umich.edu>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20231118013959.37384-1-tmgross@umich.edu
[ Added `:` before example block. ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/macros/lib.rs
rust/macros/paste.rs