Diagnostic infra doesn't respect `CLICOLOR_FORCE=1`
@Muscraft is already working on this.
Since Nov 12, 2025.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
We've recently migrated to anstream/anstyle in https://github.com/rust-lang/rust/pull/147207.
When lowering rustc's ColorConfig to anstream's/colorchoice's ColorChoice, we utilize a method called to_color_choice which interestingly isn't a straightforward 1:1 mapping as you might've thought:
Most importantly, instead of mapping Auto to Auto, it maps Auto to Never if STDERR isn't a terminal. I'm not sure why this choice was made. Regardless, it leads to us not fully utilizing anstream's "color capability detection".
For instance, it means that CLICOLOR_FORCE=1 (cc https://bixense.com/clicolors/) doesn't work: CLICOLOR_FORCE=1 rustc erroneous.rs 2>&1 >/dev/null | cat[^1] or CLICOLOR_FORCE=1 rustc erroneous.rs 2>/dev/null doesn't force color as cat / the file is a "non-terminal" and thus to_color_choice maps it to Never instead of asking anstyle-query.
Note that most if not all other detection mechanisms of anstyle-query do work for rustc/rustdoc. E.g., NO_COLOR=1 suppresses colors, TERM=dumb suppresses colors, in CI= TERM=dumb CI trumps TERM, in CLICOLOR= TERM=dumb CLICOLOR trumps TERM and so on.
[^1]: This bash (or zsh with option multios disabled) snippet redirects the stderr to a "non-terminal" (cat).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.