Syntax.ast how to create an 'as'


What does the following call look like when using syntax.ast:


I’m writing a compiler plugin, but I just can’t quite nail outputing the above code. I think I need a QSelf with position 1 as the to_string of that then shows the ‘> as <’, but then the function ‘call_on_mytrait’ is interpreted as an associated type. When I set position:0 on the QSelf and don’t include the final PathSegment then the ‘> as <’ isn’t produced.

Some(QSelf{ty:P(impl_type), position:1}),
PathSegment { span, parameters: None, identifier: Ident::from_str(“call_on_mytrait”) } ] })

Just not quite there. Alternatively is there a quote! macro for compiler plugins - I got a sniff that such a thing might once have existed on google but I couldn’t seem to import it?

(I’m doing a compiler plugin as it is my understanding that proc macros can only be used for custom derive at this moment - in my case I need to add a function to an existing trait).


It turns out that quote is a feature, not a use_macro imported from a crate:


That simplifies things!


You can use proc-macros for other things on nightly:


Ok, in proc macro land. When you have a TokenStream coming in to a proc macro as an Item, is there any way to return multiple items without wrapping them in a new module?


(For now I can look at how custom derive works.)