-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
#112697
Conversation
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
I need to tweak the wrapping text printer, it's almost there but sometimes prints slightly too much to the terminal. Do we have a standard algorithm for this anywhere already? To test with/without the pager, you can override |
This comment has been minimized.
This comment has been minimized.
c85f24a
to
0ee3834
Compare
If formatting is not possible can you keep the current markdown output? I think it is clearer than not having anything to identify code blocks. |
That is what it currently does - if |
Right, I misread the code. |
|
||
#[test] | ||
fn test_output() { | ||
let bless = std::env::var("MD_BLESS").unwrap_or_default() == "1"; |
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.
can you connect this to however x test --bless
works?
Or make it a ui
test that passes --explain
and --color=something
?
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.
I adjusted bootstrap to set RUST_BOOTSTRAP_BLESS
if --bless
is passed, so this and other tests can hook into that if needed. I think this should be an alright way to do it, but let me know if you have something better in mind.
☔ The latest upstream changes (presumably #113105) made this pull request unmergeable. Please resolve the merge conflicts. |
c050bfa
to
8e27acb
Compare
@rustbot author did anything change that I should review? |
Sorry no not yet, I was trying to figure out the best thing for that test (and got some help on zulip). |
8e27acb
to
39a53e0
Compare
29001ab
to
d8f1c4e
Compare
Alright, with that test change I think this should be good again @rustbot ready |
src/bootstrap/test.rs
Outdated
@@ -2217,6 +2217,11 @@ fn prepare_cargo_test( | |||
) -> Command { | |||
let mut cargo = cargo.into(); | |||
|
|||
// If bless is passed, give downstream crates a way to use it | |||
if std::env::args().any(|arg| arg == "--bless") { |
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.
There is a bless
flag you can check: builder.config.cmd.bless()
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.
This actually came up on Zulip the other day, Clippy and Miri kind of wanted to unite their variables that do the same thing. I did that change in #113298 and requested you for review.
I'll just checkout the relevant parts of that to this one so there's no conflict.
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.
I take this back, there wound up being some more refactoring in that that I don't want to pull into here. So I just made the change you suggested, I can adjust the other PR if this lands first. (should be good to go here again)
d8f1c4e
to
917e5b2
Compare
Currently, the output of `rustc --explain foo` displays the raw markdown in a pager. This is acceptable, but using actual formatting makes it easier to understand. This patch consists of three major components: 1. A markdown parser. This is an extremely simple non-backtracking recursive implementation that requires normalization of the final token stream 2. A utility to write the token stream to an output buffer 3. Configuration within rustc_driver_impl to invoke this combination for `--explain`. Like the current implementation, it first attempts to print to a pager with a fallback colorized terminal, and standard print as a last resort. If color is disabled, or if the output does not support it, or if printing with color fails, it will write the raw markdown (which matches current behavior). Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`), and `delta`. The markdown parser does not support the entire markdown specification, but should support the following with reasonable accuracy: - Headings, including formatting - Comments - Code, inline and fenced block (no indented block) - Strong, emphasis, and strikethrough formatted text - Links, anchor, inline, and reference-style - Horizontal rules - Unordered and ordered list items, including formatting This parser and writer should be reusable by other systems if ever needed.
917e5b2
to
6a1c10b
Compare
@bors r+ |
⌛ Testing commit 6a1c10b with merge 2e746c34b26ca2c001c862925a4c90ecd672b406... |
💔 Test failed - checks-actions |
@oli-obk could you retry? It looks like check failed downloading nodejs, server must have been iffy or something |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (6dab6dc): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 654.835s -> 655.25s (0.06%) |
This is a second attempt at #104540, which is #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 isrustc --explain E0038
)After this patch, sample output from the same file:
This also obeys the
--color always/auto/never
command option. Behavior:--color always/never
if suppliedr? @oli-obk
cc @estebank
(since the two of you were involved in the previous discussion)