diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2018-02-27 10:33:02 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2018-03-07 07:30:33 -0800 |
| commit | a919efad2e410eafe72d067b8a8d4cbe02ecb0df (patch) | |
| tree | 1d596297ca342ae1e3810691165b9ae1797211d6 /src/librustc_errors/lib.rs | |
| parent | 4cdbac639af2074b8a07b4391b4e3e28b4118487 (diff) | |
| download | rust-a919efad2e410eafe72d067b8a8d4cbe02ecb0df.tar.gz rust-a919efad2e410eafe72d067b8a8d4cbe02ecb0df.zip | |
rustc: Migrate to `termcolor` crate from `term`
This crate moves the compiler's error reporting to using the `termcolor` crate from crates.io. Previously rustc used a super-old version of the `term` crate in-tree which is basically unmaintained at this point, but Cargo has been using `termcolor` for some time now and tools like `rg` are using `termcolor` as well, so it seems like a good strategy to take! Note that the `term` crate remains in-tree for libtest. Changing libtest will be a bit tricky due to how the build works, but we can always tackle that later. cc #45728
Diffstat (limited to 'src/librustc_errors/lib.rs')
| -rw-r--r-- | src/librustc_errors/lib.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 3eea311a5af..924ed71ef0d 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -21,7 +21,8 @@ #![feature(i128_type)] #![feature(optin_builtin_traits)] -extern crate term; +extern crate atty; +extern crate termcolor; #[cfg(unix)] extern crate libc; extern crate rustc_data_structures; @@ -47,6 +48,8 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; use std::panic; +use termcolor::{ColorSpec, Color}; + mod diagnostic; mod diagnostic_builder; pub mod emitter; @@ -660,20 +663,28 @@ impl fmt::Display for Level { } impl Level { - fn color(self) -> term::color::Color { + fn color(self) -> ColorSpec { + let mut spec = ColorSpec::new(); match self { - Bug | Fatal | PhaseFatal | Error => term::color::BRIGHT_RED, + Bug | Fatal | PhaseFatal | Error => { + spec.set_fg(Some(Color::Red)) + .set_intense(true); + } Warning => { - if cfg!(windows) { - term::color::BRIGHT_YELLOW - } else { - term::color::YELLOW - } + spec.set_fg(Some(Color::Yellow)) + .set_intense(cfg!(windows)); + } + Note => { + spec.set_fg(Some(Color::Green)) + .set_intense(true); + } + Help => { + spec.set_fg(Some(Color::Cyan)) + .set_intense(true); } - Note => term::color::BRIGHT_GREEN, - Help => term::color::BRIGHT_CYAN, Cancelled => unreachable!(), } + return spec } pub fn to_str(self) -> &'static str { |
