Skip to content

Commit 9d59f5e

Browse files
Add color in rustdoc --test output
1 parent 603ab5b commit 9d59f5e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/librustdoc/doctest.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use rustc_ast as ast;
22
use rustc_data_structures::sync::Lrc;
3-
use rustc_errors::ErrorReported;
3+
use rustc_errors::{ColorConfig, ErrorReported};
4+
use rustc_feature::UnstableFeatures;
45
use rustc_hir as hir;
56
use rustc_hir::intravisit;
67
use rustc_hir::{HirId, CRATE_HIR_ID};
78
use rustc_interface::interface;
89
use rustc_middle::hir::map::Map;
910
use rustc_middle::ty::TyCtxt;
10-
use rustc_session::config::{self, CrateType};
11+
use rustc_session::config::{self, CrateType, ErrorOutputType};
1112
use rustc_session::{lint, DiagnosticOutput, Session};
1213
use rustc_span::edition::Edition;
1314
use rustc_span::source_map::SourceMap;
@@ -293,6 +294,18 @@ fn run_test(
293294
path.to_str().expect("target path must be valid unicode").to_string()
294295
}
295296
});
297+
match options.error_format {
298+
ErrorOutputType::HumanReadable(kind) => {
299+
let (_, color_config) = kind.unzip();
300+
match color_config {
301+
ColorConfig::Never => {}
302+
_ => {
303+
compiler.arg("--color").arg("always");
304+
}
305+
}
306+
}
307+
_ => {}
308+
}
296309

297310
compiler.arg("-");
298311
compiler.stdin(Stdio::piped());

0 commit comments

Comments
 (0)