Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is proc-macro2 #1005

Closed
sgrif opened this issue Jul 7, 2017 · 2 comments
Closed

What is proc-macro2 #1005

sgrif opened this issue Jul 7, 2017 · 2 comments

Comments

@sgrif
Copy link
Member

sgrif commented Jul 7, 2017

@alexcrichton @mystor

Did I do this right?

@alexcrichton
Copy link

Right now procedural methods have no method of preserving span information of expanded code or otherwise dealing with spans. That's all due to the usage of strings on both ends of the interface where you to_string a TokenStream and then parse back into a TokenStream. Clearly this isn't the best interface for all of time, so we'd like to fix that!

Upstream in rust-lang/rust the proc_macro crate is getting an enhanced API which will enable preserving and customizing span information of streams coming out of and going back into the compiler. This should be a great benefit to all procedural macros in terms of error messages and debugging usability.

All of those new APIs, however, are naturally unstable. They'll take some time to stabilize and the timeline for stabilization is unclear. To work around this the proc_macro2 crate is an attempt to sidestep this stabilization timeline. The proc_macro2 crate intends to provide the exact same API as proc_macro (if it were stable) yet also compile on stable Rust. To do that proc_macro2 by default will use the to_string and parse interfaces to convert to/from TokenStream. You can, however, enable the unstable feature of the proc_macro2 crate which actually compiles against the unstable interface of proc_macro. This requires a nightly compiler, but should be able to losslessly preserve all span information.

So basically tl;dr; proc_macro2 is future-proofing. Macros written against it have a turnkey solution for better spans on nightly today, and will have a turnkey solution for better spans in the future once the new proc_macro API is stabilized.

Does that make sense?

@sgrif
Copy link
Member Author

sgrif commented Jul 10, 2017

It does make sense, yes. So how do I get one of these

@sgrif sgrif closed this as completed Aug 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants