about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-11-17 16:13:46 +0100
committerGitHub <noreply@github.com>2020-11-17 16:13:46 +0100
commit81f9feba97adba7efc81e53a1bb0222ac977121b (patch)
tree0e2ac5e29e5f7fc05be06f4ea4f36431fa6a99ea /compiler/rustc_errors/src
parente0ef0fc392963438af5f0343bf7caa46fb9c3ec3 (diff)
parentec10824e2d2407e3addcd9877be923cc52399511 (diff)
downloadrust-81f9feba97adba7efc81e53a1bb0222ac977121b.tar.gz
rust-81f9feba97adba7efc81e53a1bb0222ac977121b.zip
Rollup merge of #74293 - GuillaumeGomez:rustdoc-test-compiler-output-color, r=jyn514
Rustdoc test compiler output color

Fixes #72915

We just need to be sure it doesn't break rustdoc doctests' compilation checks. Maybe some other unforeseen consequences too?

r? `@ehuss`
cc `@rust-lang/rustdoc`
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/emitter.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 302713a21db..32104e6f00d 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -200,6 +200,11 @@ pub trait Emitter {
         true
     }
 
+    /// Checks if we can use colors in the current output stream.
+    fn supports_color(&self) -> bool {
+        false
+    }
+
     fn source_map(&self) -> Option<&Lrc<SourceMap>>;
 
     /// Formats the substitutions of the primary_span
@@ -504,6 +509,10 @@ impl Emitter for EmitterWriter {
     fn should_show_explain(&self) -> bool {
         !self.short_message
     }
+
+    fn supports_color(&self) -> bool {
+        self.dst.supports_color()
+    }
 }
 
 /// An emitter that does nothing when emitting a diagnostic.
@@ -2057,6 +2066,14 @@ impl Destination {
             Destination::Raw(ref mut t, true) => WritableDst::ColoredRaw(Ansi::new(t)),
         }
     }
+
+    fn supports_color(&self) -> bool {
+        match *self {
+            Self::Terminal(ref stream) => stream.supports_color(),
+            Self::Buffered(ref buffer) => buffer.buffer().supports_color(),
+            Self::Raw(_, supports_color) => supports_color,
+        }
+    }
 }
 
 impl<'a> WritableDst<'a> {