Re: [PATCH v2 08/12] rust: init: add support for arbitrary paths in init macros

From: Martin Rodriguez Reboredo
Date: Thu Jul 20 2023 - 20:26:25 EST


On 7/19/23 11:21, Benno Lossin wrote:
Previously only `ident` and generic types were supported in the
`{try_}{pin_}init!` macros. This patch allows arbitrary path fragments,
so for example `Foo::Bar` but also very complex paths such as
`<Foo as Baz>::Bar::<0, i32>`.

Internally this is accomplished by using `path` fragments. Due to some
peculiar declarative macro limitations, we have to "forget" certain
additional parsing information in the token trees. This is achieved by
using the `paste!` proc macro. It does not actually modify the input,
since no `[< >]` will be present in the input, so it just strips the
information held by declarative macros. For example, if a declarative
macro takes `$t:path` as its input, it cannot sensibly propagate this to
a macro that takes `$($p:tt)*` as its input, since the `$t` token will
only be considered one `tt` token for the second macro. If we first pipe
the tokens through `paste!`, then it parses as expected.

Suggested-by: Asahi Lina <lina@xxxxxxxxxxxxx>
Signed-off-by: Benno Lossin <benno.lossin@xxxxxxxxx>
---
[...]
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@xxxxxxxxx>