I ran into this error and thought my very hacky workaround might be of use to someone.
Suppose I have some code (playground) which looks like this:
#[macro_use]
extern crate quote;
extern crate syn;
extern crate proc_macro2; // 1.0.24
fn main() {
let x = vec![
quote! {let x = 1;},
quote! {let x = 2;}
];
println!("{:#?}", quote! {
#x
});
}
This doesn't compile.
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `Vec<TokenStream2>: ToTokens` is not satisfied
--> src/main.rs:11:23
|
11 | println!("{:#?}", quote! {
| _______________________^
12 | | #x
13 | | });
| |_____^ the trait `ToTokens` is not implemented for `Vec<TokenStream2>`
|
= note: required by `to_tokens`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
How do I use quote! to concatenate a Vec<proc_macro2::TokenStream>?