rust-lang / rust-lang/rust

Diagnostic infra doesn't respect `CLICOLOR_FORCE=1`

Open
#148,864 2 comments 0 reactions 1 assignee View on GitHub

@Muscraft is already working on this.

Since Nov 12, 2025.

C-bug D-diagnostic-infra T-compiler T-rustdoc
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:

https://github.com/rust-lang/rust/blob/95aeb4696545eb4c9cbb68516f2912770e3846ea/compiler/rustc_errors/src/emitter.rs#L591-L604

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.