@@ -8,8 +8,8 @@ use std::sync::Arc;
88use rustc_ast:: token:: { Delimiter , TokenKind } ;
99use rustc_ast:: tokenstream:: TokenTree ;
1010use rustc_ast:: { self as ast, AttrStyle , HasAttrs , StmtKind } ;
11- use rustc_errors:: emitter:: stderr_destination ;
12- use rustc_errors:: { AutoStream , ColorConfig , DiagCtxtHandle } ;
11+ use rustc_errors:: emitter:: get_stderr_color_choice ;
12+ use rustc_errors:: { AutoStream , ColorChoice , ColorConfig , DiagCtxtHandle } ;
1313use rustc_parse:: lexer:: StripTokens ;
1414use rustc_parse:: new_parser_from_source_str;
1515use rustc_session:: parse:: ParseSess ;
@@ -446,7 +446,7 @@ fn parse_source(
446446 span : Span ,
447447) -> Result < ParseSourceInfo , ( ) > {
448448 use rustc_errors:: DiagCtxt ;
449- use rustc_errors:: emitter:: { Emitter , HumanEmitter } ;
449+ use rustc_errors:: emitter:: HumanEmitter ;
450450 use rustc_span:: source_map:: FilePathMapping ;
451451
452452 let mut info =
@@ -458,9 +458,12 @@ fn parse_source(
458458
459459 let sm = Arc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
460460 let translator = rustc_driver:: default_translator ( ) ;
461- info. supports_color =
462- HumanEmitter :: new ( stderr_destination ( ColorConfig :: Auto ) , translator. clone ( ) )
463- . supports_color ( ) ;
461+ let supports_color = match get_stderr_color_choice ( ColorConfig :: Auto , & std:: io:: stderr ( ) ) {
462+ ColorChoice :: Auto => unreachable ! ( ) ,
463+ ColorChoice :: AlwaysAnsi | ColorChoice :: Always => true ,
464+ ColorChoice :: Never => false ,
465+ } ;
466+ info. supports_color = supports_color;
464467 // Any errors in parsing should also appear when the doctest is compiled for real, so just
465468 // send all the errors that the parser emits directly into a `Sink` instead of stderr.
466469 let emitter = HumanEmitter :: new ( AutoStream :: never ( Box :: new ( io:: sink ( ) ) ) , translator) ;
0 commit comments