-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 -Zast and -Zast-noexpand to pretty-print AST (without the JSON conversion) #38083
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
r? @nrc |
I'd like to see an example output. |
|
Could this be a pretty printing option rather than a |
Is that the right place to put it? The |
Ah, I see now that there's already |
This is working now: fn main() {
println!("Hello, World!");
go(there);
}
However, the printing of statements isn't very useful for exploring the AST:
This is because impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "stmt({}: {})", self.id.to_string(), pprust::stmt_to_string(self))
}
} Is there a good way around this? |
I don't think there is a good way around this. You could try creating your own trait and use specialisation so that by default is calls the debug implementation, but you override this for statements and expressions. I'm not sure if that will work though, it might fall foul of the specialisation/coherence rules. You could also just change the debug impls for Stmt and Expr, I'm not sure how the rest of @rust-lang/compiler feel, but I'd prefer Debug to contain what you want and maybe implement Display for the current stuff. |
Definitely agree with keeping |
Hmm. I...agree with auto-generating Debug, though I do find it really useful to be able to search the RUST_LOG output for specific expressions. I do this all the time when tracking down type-checking or region-inference failures. Probably the solution is to change a lot of those debug logs to |
Ping! It's been a month since there's been any activity on this PR; can we move it forward? |
I think the main consideration here is whether |
☔ The latest upstream changes (presumably #39199) made this pull request unmergeable. Please resolve the merge conflicts. |
-Zast behaves like -Zast-json but uses {:#?} pretty-printing instead of converting to JSON. -Zast-noexpand is the pretty-printing counterpart to -Zast-json-noexpand.
I don't think I'm familiar enough with the |
@spinda @steveklabnik can someone close this? |
Will do. |
-Zast behaves like -Zast-json but uses
{:#?}
pretty-printing instead of converting to JSON.-Zast-noexpand is the pretty-printing counterpart to -Zast-json-noexpand.
Fixes #37873.