Macro metavar expr concat doesn't work with nested repetitions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Is it a known issue that this doesn't seem to work with identifiers repeating at a depth?
#![feature(macro_metavar_expr_concat)]
macro_rules! many_idents {
($a:ident, $c:ident) => {
const ${concat($a, B, $c, D)}: i32 = 1;
};
}
// Paste implementation included for reference
macro_rules! many_idents_paste {
($a:ident, $c:ident) => {
paste::paste! {
const [<$a B $c D>]: i32 = 2;
}
};
}
macro_rules! many_idents_multi_metavar {
($($a:ident, $c:ident;)*) => {
$(
const ${concat($a, B, $c, D)}: i32 = 3;
)*
};
}
// Paste implementation included for reference
macro_rules! many_idents_multi_paste {
($($a:ident, $c:ident;)*) => {
$(
paste::paste! {
const [<$a B $c D>]: i32 = 3;
}
)*
};
}
fn main() {
many_idents!(A, C);
assert_eq!(ABCD, 1);
many_idents_paste!(F, G);
assert_eq!(FBGD, 2);
many_idents_multi_paste! {
H, I;
J, K;
L, M;
}
assert_eq!(HBID, 3);
assert_eq!(JBKD, 3);
assert_eq!(LBMD, 3);
many_idents_multi_metavar! {
N, O;
P, Q;
R, S;
}
}
error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
--> src/main.rs:19:10
|
19 | $(
| __________^
20 | | const ${concat($a, B, $c, D)}: i32 = 3;
21 | | )*
| |_________^
The paste version works without errors.
I can go a bit further with ignore
macro_rules! many_idents_multi_metavar {
($($a:ident, $c:ident;)*) => {
$(
${ignore($a)}
${ignore($c)}
const ${concat($a, B, $c, D)}: i32 = 3;
)*
};
}
But then I get:
error: `${concat(..)}` currently only accepts identifiers or meta-variables as parameters
--> src/main.rs:22:29
|
22 | const ${concat($a, B, $c, D)}: i32 = 3;
|
This seems like a major limitation.
Originally posted by @crumblingstatue in https://github.com/rust-lang/rust/issues/124225#issuecomment-2180345042
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure using the Rust example in src/main.rs, focusing on macro_metavar_expr_concat inside nested repetitions. Compare the behavior with the paste implementation and the version using ignore. Done means the multi-metavariable macro expands successfully and the generated identifiers satisfy the shown assertions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100