How to get a proc_macro::TokenStream out of quote? [solved]

This feels really stupid, but I can’t for the heck of me figure out how to get a TokenStream out of the quote::Tokens that is given by quote!(foo). I get an error like

error[E0277]: the trait bound `proc_macro::TokenStream: std::convert::From<quote::Tokens>` is not satisfied
  --> display-as-proc-macro/src/                                             
16 |     TokenStream::from(s)                                                           
   |     ^^^^^^^^^^^^^^^^^ the trait `std::convert::From<quote::Tokens>` is not implemented for `proc_macro::TokenStream`
   = help: the following implementations were found:                                    
             <proc_macro::TokenStream as std::convert::From<proc_macro::TokenTree>>     
   = note: required by `std::convert::From::from`                                                                                    

Any hints?

1 Like

Seems to work in the playground. What does your Cargo.toml look like?

As it turns out, the problem is that for some reason (I’m presuming a bad copy-and-paste) I had quote = "0.3.15", and when I changed it to “0.6.0” the problem vanished. Thanks for the hint!

Okay, now I’ve gotten another (probably related?) error. I’m having trouble including a TokenStream in a quote. Here is a playground link that illustrates the problem. Again, I expect the solution is obvious, but it has eluded me…

The error, BTW, is:

the trait `quote::ToTokens` is not implemented for `proc_macro::TokenStream
1 Like

The quote macro only manipulates proc-macro2 types so you will want to write all code involving quote in terms of proc-macro2 types only (i.e. proc_macro2::TokenStream).