-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 simple markdown formatting to rustc --explain
output
#104540
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
cc @rust-lang/wg-diagnostics |
I feel like it'd be reasonable to pull in a markdown parser if there was a reasonable one (small, maintained) with a compatible license for this. Also, you might be interested in seeing if this very old PR would be still usable for code highlighting: #39300. |
After talking with Oli, I'm ok with using regexes for this, given that there will be no adversarial content. |
rustc_errors makes sense to me
I think what you want to look at is
This is what rustc does rust/compiler/rustc_errors/src/emitter.rs Line 629 in 52cc0d5
|
@rustbot author |
1562c27
to
acfde73
Compare
acfde73
to
cc9e76e
Compare
I have a few tweaks to make but I'll mark this as ready for review to get some feedback at this point. It turned out that a super simple parser was somewhat easier to get right than markdown, so I went that route instead (still use regex to parse
Still todo:
Example output from E0038: And generic example: I saw your comment @estebank about 39300 for code formatting, but I'd like to reintroduce that in a separate PR if that's ok, just to keep this one scoped. It will be easy to plug in separately |
#![warn(clippy::pedantic)] | ||
#![warn(clippy::nursery)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, we don't use clippy on rustc yet.
☔ The latest upstream changes (presumably #105890) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this. @rustbot label: +S-inactive |
Sorry about that, it's been on my todo list but I just haven't gotten to it. Good decision, I will revisit at a later time 👍 |
Add simple markdown formatting to `rustc --explain` output This is a second attempt at rust-lang#104540, which is rust-lang#63128 without dependencies. This PR adds basic markdown formatting to `rustc --explain` output when available. Currently, the output just displays raw markdown: this works of course, but it really doesn't look very elegant. (output is `rustc --explain E0038`) <img width="583" alt="image" src="https://github.com/rust-lang/rust/assets/13724985/ea418117-47af-455b-83c0-6fc59276efee"> After this patch, sample output from the same file: <img width="693" alt="image" src="https://github.com/rust-lang/rust/assets/13724985/12f7bf9b-a3fe-4104-b74b-c3e5227f3de9"> This also obeys the `--color always/auto/never` command option. Behavior: - If pager is available and supports color, print with formatting to the pager - If pager is not available or fails print with formatting to stdout - otherwise without formatting - Follow `--color always/never` if suppied - If everything fails, just print plain text to stdout r? `@oli-obk` cc `@estebank` (since the two of you were involved in the previous discussion)
The goal here is to provide some sort of super basic markdown formatting to
rustc --explain
output when available. This is a minimal alternative to #63128 without additiional dependencies.There's a lot of tweaking to do but I'm creating this draft PR because I could use some guidance on things like:
rustc_driver
because that's wherehandle_explain
is called, but it might make sense inrustc_errors
which currently does some output formattingWritableDst
inrustc_errors/src/emitter.rs
? It seems like this is used to indicate TTY-ness, but I can't find it in use anywhereCurrently, the output just displays raw markdown. This works of course, but it really doesn't look very elegant. (output is
rustc --explain E0038
)After this patch, sample output from the same file: