Skip to content

Commit 893c4b4

Browse files
authored
Rollup merge of #148834 - Muscraft:fix-doctest-colors, r=fmease
fix(rustdoc): Color doctest errors `@fmease's` [Deep analysis](rust-lang/rust#148749 (comment)) on the problem > Yeah, here's a deep analysis by me from a few weeks back of what's going on ([#148101 (comment)](rust-lang/rust#148101 (comment))): > > > […] > > However, since said PR ([#147207](rust-lang/rust#147207): migrating coloring crates), `HumanEmitter::supports_color()` unconditionally(!) returns `false` (in fact, `Emitter::supports_color` is no longer used by anyone else and should be removed), so there's no reason to keep it. Rephrased, since that PR all compiler diagnostics for doctests are uncolored. > > You could argue that I should keep it and patch `supports_color` in rustc to "work again". However, I'd rather rework our doctest coloring wholesale in a separate PR. At least before that migration PR, our setup was quite busted: > > > > 1. First of all, it didn't query+set `supports_color` for syntactically invalid doctests, so syntax errors were always shown without color (contrary to e.g., name resolution errors). > > 2. Second of all, calling `supports_color()` here was quite frankly wrong: Piping the output of `rustdoc … --test` into a file (or `| cat` or whatever) did **not** suppress colors. I'm not actually sure if we can ever address that nicely (without stripping ANSI codes after the fact) since we pass that diagnostic to `libtest`, right? I might very well be wrong here, maybe it's a non-issue. <hr> ```rust /// ``` /// foo /// ``` fn foo() {} ``` ``` rustdoc --test lib.rs ``` Stable: <img width="377" height="290" alt="stable" src="https://github.com/user-attachments/assets/cd20f947-b58d-42db-8735-797613baa9cc" /> Beta: <img width="377" height="290" alt="beta" src="https://github.com/user-attachments/assets/f02588fd-41d2-4642-b03a-5554a68671eb" /> Nightly: <img width="377" height="290" alt="nightly" src="https://github.com/user-attachments/assets/871cb417-f47e-4058-8a76-3bcd538ce141" /> After: <img width="377" height="290" alt="after" src="https://github.com/user-attachments/assets/5734c01f-3f1c-44bb-9404-628c0c33b440" /> Note: This will need to be backported to `beta` Fixes: rust-lang/rust#148749
2 parents 1f6b1db + 4ce5ac8 commit 893c4b4

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)