@@ -12,6 +12,7 @@ use rustc_span::{
1212} ;
1313
1414use crate :: config:: file_lines:: LineRange ;
15+ use crate :: config:: options:: Color ;
1516use crate :: ignore_path:: IgnorePathSet ;
1617use crate :: parse:: parser:: { ModError , ModulePathSuccess } ;
1718use crate :: source_map:: LineRangeUtils ;
@@ -107,15 +108,26 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
107108 }
108109}
109110
111+ impl From < Color > for ColorConfig {
112+ fn from ( color : Color ) -> Self {
113+ match color {
114+ Color :: Auto => ColorConfig :: Auto ,
115+ Color :: Always => ColorConfig :: Always ,
116+ Color :: Never => ColorConfig :: Never ,
117+ }
118+ }
119+ }
120+
110121fn default_handler (
111122 source_map : Lrc < SourceMap > ,
112123 ignore_path_set : Lrc < IgnorePathSet > ,
113124 can_reset : Lrc < AtomicBool > ,
114125 hide_parse_errors : bool ,
126+ color : Color ,
115127) -> Handler {
116128 let supports_color = term:: stderr ( ) . map_or ( false , |term| term. supports_color ( ) ) ;
117- let color_cfg = if supports_color {
118- ColorConfig :: Auto
129+ let emit_color = if supports_color {
130+ ColorConfig :: from ( color )
119131 } else {
120132 ColorConfig :: Never
121133 } ;
@@ -126,7 +138,7 @@ fn default_handler(
126138 let fallback_bundle =
127139 rustc_errors:: fallback_fluent_bundle ( rustc_errors:: DEFAULT_LOCALE_RESOURCES , false ) ;
128140 Box :: new ( EmitterWriter :: stderr (
129- color_cfg ,
141+ emit_color ,
130142 Some ( source_map. clone ( ) ) ,
131143 None ,
132144 fallback_bundle,
@@ -164,6 +176,7 @@ impl ParseSess {
164176 Lrc :: clone ( & ignore_path_set) ,
165177 Lrc :: clone ( & can_reset_errors) ,
166178 config. hide_parse_errors ( ) ,
179+ config. color ( ) ,
167180 ) ;
168181 let parse_sess = RawParseSess :: with_span_handler ( handler, source_map) ;
169182
0 commit comments