Commit 84a8d2a
committed
rust: macros: paste: add support for using var as part of group
The following code is currently working fine and will generate a struct
named "Test0":
kernel::macros::paste! {
struct [<Test 0>];
}
But if we need to use a "macro variable" like this:
macro_rules! test {
($i: literal) => {
kernel::macros::paste! {
struct [<Test $i>];
}
};
}
test!(0);
The code above will make the paste! macro panic:
error: proc macro panicked
--> drivers/regulator/ncv6336.rs:25:9
|
25 | / kernel::macros::paste! {
26 | | struct [<Test $i>];
27 | | }
| |_________^
...
31 | test!(0);
| -------- in this macro invocation
|
= help: message: unexpected token in paste segments
The reason of this panic is that "macro variables" are creating
`Groups` [0], with the `None` delimiter [1], and currently `Groups`are not
handled by the paste! macro.
This commit adds support for TokenTree::Group token where the delimiter
is None in order to make the previous code snippet now work.
[0] https://doc.rust-lang.org/proc_macro/struct.Group.html
[1] https://doc.rust-lang.org/proc_macro/enum.Delimiter.html#variant.None
Signed-off-by: Fabien Parent <[email protected]>1 parent 1cf952d commit 84a8d2a
1 file changed
+20
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
49 | 63 | | |
50 | 64 | | |
51 | 65 | | |
52 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
53 | 72 | | |
54 | 73 | | |
55 | 74 | | |
| |||
0 commit comments