about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustdoc/Cargo.toml3
-rw-r--r--src/librustdoc/doctest.rs25
-rw-r--r--src/librustdoc/lib.rs4
3 files changed, 30 insertions, 2 deletions
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml
index b0f5bac6abd..085f155ec25 100644
--- a/src/librustdoc/Cargo.toml
+++ b/src/librustdoc/Cargo.toml
@@ -20,3 +20,6 @@ regex = "1"
 
 [dev-dependencies]
 expect-test = "1.0"
+
+[target.'cfg(windows)'.dependencies]
+termcolor = "1.0"
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index 478a72f400a..d1219c30b89 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -298,10 +298,31 @@ fn run_test(
         ErrorOutputType::HumanReadable(kind) => {
             let (_, color_config) = kind.unzip();
             match color_config {
-                ColorConfig::Never => {}
-                _ => {
+                ColorConfig::Never => {
+                    compiler.arg("--color").arg("never");
+                }
+                ColorConfig::Always => {
                     compiler.arg("--color").arg("always");
                 }
+                ColorConfig::Auto => {
+                    #[cfg(windows)]
+                    {
+                        // This specific check is because old windows consoles require a connection
+                        // to be able to display colors (and they don't support ANSI), which we
+                        // cannot in here, so in case this is an old windows console, we can't
+                        // display colors.
+                        use crate::termcolor::{ColorChoice, StandardStream, WriteColor};
+                        if StandardStream::stdout(ColorChoice::Auto).is_synchronous() {
+                            compiler.arg("--color").arg("never");
+                        } else {
+                            compiler.arg("--color").arg("always");
+                        }
+                    }
+                    #[cfg(not(windows))]
+                    {
+                        compiler.arg("--color").arg("always");
+                    }
+                }
             }
         }
         _ => {}
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index a88efba77b4..1f46ac59e6a 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -54,6 +54,10 @@ extern crate rustc_target;
 extern crate rustc_trait_selection;
 extern crate rustc_typeck;
 extern crate test as testing;
+#[macro_use]
+extern crate tracing;
+#[cfg(windows)]
+extern crate termcolor;
 
 use std::default::Default;
 use std::env;