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

Add a way to see expanded macros #158

Closed
Diggsey opened this issue Jul 11, 2017 · 11 comments
Closed

Add a way to see expanded macros #158

Diggsey opened this issue Jul 11, 2017 · 11 comments
Labels
enhancement Something new the playground could do help wanted Not immediately going to be prioritized — ask for mentoring instructions!

Comments

@Diggsey
Copy link

Diggsey commented Jul 11, 2017

There's currently no way to experiment with macro_rules online. I think having a --pretty=expanded option on the playground would be great.

@shepmaster
Copy link
Member

An interesting idea! Is that a stable flag, do you know?

Any suggestions or hastily mocked-up drawings for how this could fit in the UI?

@shepmaster shepmaster added enhancement Something new the playground could do help wanted Not immediately going to be prioritized — ask for mentoring instructions! labels Jul 12, 2017
@shepmaster shepmaster changed the title Feature: macro expand Add a way to see expanded macros Jul 12, 2017
@Diggsey
Copy link
Author

Diggsey commented Jul 12, 2017

It's an unstable flag.

I imagine it could sit within the tools group, and act similarly to Format. (You can therefore use "undo" to un-expand the macros).

It's probably worth running it through the formatter as part of the expansion, or maybe use cargo-expand which does this already.

@joshtriplett
Copy link
Member

I'd really like to see this as well.

@shepmaster This should sit next to Clippy, and open another output tab labeled "Expanded Macros" or similar. I don't think it makes sense to change the original code; this should be an output format. For a first pass, it can just dump the output directly into an output tab. As a second pass, it'd be incredible to have a diff-like mechanism that lets you move through the code on the left and highlight the corresponding expanded span on the right. The compiler has that information; you'd just need to dump it and turn it into JSON to hand to the client.

@joshtriplett
Copy link
Member

rust-lang/rust#43364

@tomwhoiscontrary
Copy link

I was looking for this feature just now. The first place i looked was in the "WHAT DO YOU WANT TO DO?" menu next to the build button, because macro-expanded pseudo-source feels like a kind of intermediate output, like MIR or LLVM IR. The second place i looked was in the "Tools" menu, because that's where random useful things live. The playground's UI is small enough that people will probably find it soon enough, wherever it is!

From the discussion on rust-lang/rust#43364, it sounds like the rustc flag won't be stabilised any time soon. Could this be an option which only works on nightly? I wouldn't mind that.

About formatting, the discussion on rust-lang/rust#43364 includes a comment about "an issue where a macro expansion results in unparseable output". So perhaps it's unwise to assume that the output can always be formatted, and either not format it at all, or handle failure, or make it optional.

@peterjoel
Copy link

It would be useful even it it was just an "Expand Macros" option under "Tools", which create a tab in the right pane, with unformatted text in it.

@spease
Copy link

spease commented May 9, 2019

I'd also like to see this, I believe it'd be useful for derives

@nagisa
Copy link
Member

nagisa commented Jun 10, 2019

Wanted.

@Flowneee
Copy link
Contributor

@shepmaster I attempted to implement this feature in #599. It currently very simple and don't include any option to format output, also rely on nightly compiler.

@shepmaster
Copy link
Member

Closed via #599

@tomwhoiscontrary
Copy link

@Flowneee Fantastic, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something new the playground could do help wanted Not immediately going to be prioritized — ask for mentoring instructions!
Projects
None yet
Development

No branches or pull requests

8 participants