diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-29 14:47:09 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-29 17:16:27 +1100 |
| commit | 437325bdd4e5fc54b0f78491e63fa386ebfffbba (patch) | |
| tree | 942dc0944a53c3c0b3c99b9f436ca0743d9d0d3f /compiler/rustc_errors/src/json.rs | |
| parent | d3727413ed96a8feedcca9931b9b8abb72632492 (diff) | |
| download | rust-437325bdd4e5fc54b0f78491e63fa386ebfffbba.tar.gz rust-437325bdd4e5fc54b0f78491e63fa386ebfffbba.zip | |
Inline and remove `HumanReadableErrorType::new_emitter`.
And likewise with `ColorConfig::suggests_using_colors`. They both have a single call site. And note that `BufWriter::supports_color()` always returns false, which enables a small bit of constant folding along the way.
Diffstat (limited to 'compiler/rustc_errors/src/json.rs')
| -rw-r--r-- | compiler/rustc_errors/src/json.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index 94d0c5d060e..ab2ed5ebaeb 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -12,7 +12,10 @@ use rustc_span::source_map::{FilePathMapping, SourceMap}; use termcolor::{ColorSpec, WriteColor}; -use crate::emitter::{should_show_source_code, Emitter, HumanReadableErrorType}; +use crate::emitter::{ + should_show_source_code, ColorConfig, Destination, Emitter, HumanEmitter, + HumanReadableErrorType, +}; use crate::registry::Registry; use crate::translation::{to_fluent_args, Translate}; use crate::{ @@ -405,8 +408,17 @@ impl Diagnostic { .collect(); let buf = BufWriter::default(); - je.json_rendered - .new_emitter(Box::new(buf.clone()), je.fallback_bundle.clone()) + let mut dst: Destination = Box::new(buf.clone()); + let (short, color_config) = je.json_rendered.unzip(); + let color = match color_config { + ColorConfig::Always | ColorConfig::Auto => true, + ColorConfig::Never => false, + }; + if color { + dst = Box::new(termcolor::Ansi::new(dst)); + } + HumanEmitter::new(dst, je.fallback_bundle.clone()) + .short_message(short) .sm(Some(je.sm.clone())) .fluent_bundle(je.fluent_bundle.clone()) .diagnostic_width(je.diagnostic_width) |
