Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport duplicate interpolations inside a repetition #8
Comments
dtolnay
added
the
enhancement
label
Oct 9, 2016
This comment has been minimized.
This comment has been minimized.
|
I don't think this is possible with Rewriting |
This comment has been minimized.
This comment has been minimized.
purpleposeidon
commented
Feb 25, 2017
•
|
This is the work-around I have been using for this issue:
|
This comment has been minimized.
This comment has been minimized.
purpleposeidon
commented
Feb 25, 2017
|
Nope, that doesn't actually compile! #[macro_use]
extern crate quote;
fn main() {
let foo: Vec<&str> = Vec::new();
let foo2 = &foo;
quote! {
#(#foo #foo2)*
};
}
--pretty expanded makes it obvious why: fn main() {
let foo: Vec<&str> = Vec::new();
let foo2 = &foo;
{
let mut _s = $crate::Tokens::new();
for (foo, foo2) in foo.into_iter().zip(foo2) {
$crate::ToTokens::to_tokens(&foo, &mut _s);
$crate::ToTokens::to_tokens(&foo2, &mut _s);
};
_s
};
} |
This comment has been minimized.
This comment has been minimized.
let ref foo: Vec<&str> = Vec::new();
let foo2 = foo;
quote! {
#(#foo #foo2)*
}; |
This comment has been minimized.
This comment has been minimized.
JeanMertz
commented
Sep 11, 2018
•
|
For reference, I ran into this today. I am porting a fairly complex Since funclike proc-macro's are (almost?) a thing now, perhaps it's time to start thinking about that rewrite for
Not sure why I didn't realise the post above was the current workaround, but that works as expected |
added a commit
to ohua-dev/ohua-rust-runtime
that referenced
this issue
Dec 14, 2018
This comment has been minimized.
This comment has been minimized.
|
Closing as an acknowledged limitation that I don't intend to fix. dtolnay/request-for-implementation#8 tracks a procedural macro reimplementation of quote (as a separate library) which will be able to avoid this limitation. Maybe crates that hit this especially often will opt to use the other library. The recommended workaround is to use references with distinct names inside the repetition. let a: Vec<_> = /* ... */;
let a1 = &a;
let a2 = &a;
quote! {
#(#a1 #a2)*
}; |
dtolnay
closed this
Jan 28, 2019
This comment has been minimized.
This comment has been minimized.
|
Added an indication of the limitation in the docs: f81fdb4. |
dtolnay commentedOct 9, 2016
quote! { #a #a }works butquote! { #(#a #a)* }does not.