Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
efe703a
[self-profiling] Include the estimated size of each cgu in the profile
wesleywiser Nov 3, 2020
279bf29
Get rid of `Class::None`
jyn514 Nov 15, 2020
74d5466
update rustfmt to v1.4.27
calebcartwright Nov 17, 2020
b3f9795
Get rid of clean::TyMethod
jyn514 Nov 17, 2020
2a991e1
Get rid of clean::Method
jyn514 Nov 17, 2020
5903163
Remove duplicate `Trait::auto` field
jyn514 Nov 17, 2020
a1cdf72
Fix exhaustiveness in case a byte string literal is used at slice type
oli-obk Nov 15, 2020
5f2a627
extend macro braces test
lcnr Nov 17, 2020
96a6a5f
Add color in rustdoc --test output
GuillaumeGomez Jul 13, 2020
54e8216
Update error code detection in compile_fail doctests
GuillaumeGomez Jul 14, 2020
57bab5e
Add check to get windows console type to decide to use colors or not
GuillaumeGomez Jul 16, 2020
704001b
Update lock file
GuillaumeGomez Jul 16, 2020
32d64ed
Simplfy color availability check
GuillaumeGomez Nov 11, 2020
fd4a33c
Update doctest tests
GuillaumeGomez Nov 11, 2020
95ee1fc
Correctly detect color support
GuillaumeGomez Nov 12, 2020
63785c8
Add comment explaining why we can't split on `error[{}]: ` because of…
GuillaumeGomez Nov 13, 2020
ec10824
Remove unused import
GuillaumeGomez Nov 15, 2020
81f9feb
Rollup merge of #74293 - GuillaumeGomez:rustdoc-test-compiler-output-…
m-ou-se Nov 17, 2020
fa45fce
Rollup merge of #78702 - wesleywiser:self_profile_cgu_sizes, r=Mark-S…
m-ou-se Nov 17, 2020
dda4798
Rollup merge of #79069 - jyn514:class-none, r=GuillaumeGomez
m-ou-se Nov 17, 2020
b6f5241
Rollup merge of #79072 - oli-obk:byte_str_pat, r=estebank
m-ou-se Nov 17, 2020
53ddb73
Rollup merge of #79120 - calebcartwright:update-rustfmt, r=Mark-Simul…
m-ou-se Nov 17, 2020
3d63f25
Rollup merge of #79125 - jyn514:fewer-types, r=GuillaumeGomez
m-ou-se Nov 17, 2020
ca38bd4
Rollup merge of #79126 - jyn514:auto, r=GuillaumeGomez
m-ou-se Nov 17, 2020
f698505
Rollup merge of #79130 - lcnr:extend-tes, r=varkor
m-ou-se Nov 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplfy color availability check
  • Loading branch information
GuillaumeGomez committed Nov 17, 2020
commit 32d64edcf9d31ded609ab70b31bd3779d6f85ec1
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4301,7 +4301,6 @@ dependencies = [
"serde_json",
"smallvec 1.4.2",
"tempfile",
"termcolor",
]

[[package]]
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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> {
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ regex = "1"

[dev-dependencies]
expect-test = "1.0"

[target.'cfg(windows)'.dependencies]
termcolor = "1.0"
58 changes: 22 additions & 36 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ fn run_test(
outdir: DirState,
path: PathBuf,
) -> Result<(), TestFailure> {
let (test, line_offset) = make_test(test, Some(cratename), as_test_harness, opts, edition);
let (test, line_offset, supports_color) =
make_test(test, Some(cratename), as_test_harness, opts, edition);

let output_file = outdir.path().join("rust_out");

Expand Down Expand Up @@ -294,38 +295,19 @@ fn run_test(
path.to_str().expect("target path must be valid unicode").to_string()
}
});
match options.error_format {
ErrorOutputType::HumanReadable(kind) => {
let (_, color_config) = kind.unzip();
match color_config {
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");
}
}
if let ErrorOutputType::HumanReadable(kind) = options.error_format {
let (_, color_config) = kind.unzip();
match color_config {
ColorConfig::Never => {
compiler.arg("--color").arg("never");
}
ColorConfig::Always => {
compiler.arg("--color").arg("always");
}
ColorConfig::Auto => {
compiler.arg("--color").arg(if supports_color { "always" } else { "never" });
}
}
_ => {}
}

compiler.arg("-");
Expand Down Expand Up @@ -396,18 +378,19 @@ fn run_test(
}

/// Transforms a test into code that can be compiled into a Rust binary, and returns the number of
/// lines before the test code begins.
/// lines before the test code begins as well as if the output stream supports colors or not.
crate fn make_test(
s: &str,
cratename: Option<&str>,
dont_insert_main: bool,
opts: &TestOptions,
edition: Edition,
) -> (String, usize) {
) -> (String, usize, bool) {
let (crate_attrs, everything_else, crates) = partition_source(s);
let everything_else = everything_else.trim();
let mut line_offset = 0;
let mut prog = String::new();
let mut supports_color = false;

if opts.attrs.is_empty() && !opts.display_warnings {
// If there aren't any attributes supplied by #![doc(test(attr(...)))], then allow some
Expand All @@ -433,7 +416,7 @@ crate fn make_test(
// crate already is included.
let result = rustc_driver::catch_fatal_errors(|| {
rustc_span::with_session_globals(edition, || {
use rustc_errors::emitter::EmitterWriter;
use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::Handler;
use rustc_parse::maybe_new_parser_from_source_str;
use rustc_session::parse::ParseSess;
Expand All @@ -447,6 +430,9 @@ crate fn make_test(
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let emitter =
EmitterWriter::new(box io::sink(), None, false, false, false, None, false);

supports_color = emitter.supports_color();

// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
let handler = Handler::with_emitter(false, None, box emitter);
let sess = ParseSess::with_span_handler(handler, sm);
Expand Down Expand Up @@ -516,7 +502,7 @@ crate fn make_test(
Err(ErrorReported) => {
// If the parser panicked due to a fatal error, pass the test code through unchanged.
// The error will be reported during compilation.
return (s.to_owned(), 0);
return (s.to_owned(), 0, false);
}
};

Expand Down Expand Up @@ -566,7 +552,7 @@ crate fn make_test(

debug!("final doctest:\n{}", prog);

(prog, line_offset)
(prog, line_offset, supports_color)
}

// FIXME(aburka): use a real parser to deal with multiline attributes
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
.collect::<Vec<Cow<'_, str>>>()
.join("\n");
let krate = krate.as_ref().map(|s| &**s);
let (test, _) = doctest::make_test(&test, krate, false, &Default::default(), edition);
let (test, _, _) =
doctest::make_test(&test, krate, false, &Default::default(), edition);
let channel = if test.contains("#![feature(") { "&amp;version=nightly" } else { "" };

let edition_string = format!("&amp;edition={}", edition);
Expand Down
4 changes: 0 additions & 4 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ 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;
Expand Down