proc_macro::quote does not work with interpolated constant inside repetition
Open
Nobody has claimed this yet.
A-proc-macros
C-bug
F-proc_macro_quote
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
A constant N can be interpolated as $N inside quote, but not inside a repetition. I believe this should be supported.
#![feature(proc_macro_quote)]
use proc_macro::{quote, TokenStream};
const N: usize = 8;
#[proc_macro]
pub fn repro(_input: TokenStream) -> TokenStream {
let ok = '?';
let array = ['0', '1', '2'];
let tokens = quote! {
// Okay
... $ok $N ...
// Okay
$($ok $array)*
// Fail
$($N $array)*
};
eprintln!("{}", tokens);
TokenStream::new()
}
error[E0530]: let bindings cannot shadow constants
--> src/lib.rs:19:12
|
5 | const N: usize = 8;
| ------------------- the constant `N` is defined here
...
19 | $($N $array)*
| ^ cannot be named the same as a constant
Expected output:
... '?' 8usize ... '?' '0' '?' '1' '?' '2' 8usize '0' 8usize '1' 8usize '2'
- Tracking issue: https://github.com/rust-lang/rust/issues/54722
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
Start with the reproducer in src/lib.rs and run the proc_macro::quote example to confirm the failure and expected token output. Trace how quote handles interpolation inside repetitions, using the diagnostic and linked tracking issue #54722 as context. Done means constants interpolate correctly inside repetitions without the shadowing error.
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
- Clearly specified
- Newbie friendliness
- 48/100