@@ -19,6 +19,7 @@ use syntax::parse::token;
1919use syntax:: parse;
2020use syntax:: symbol:: Symbol ;
2121use syntax:: feature_gate:: UnstableFeatures ;
22+ use errors:: emitter:: HumanReadableErrorType ;
2223
2324use errors:: { ColorConfig , FatalError , Handler } ;
2425
@@ -204,19 +205,18 @@ impl OutputType {
204205
205206#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
206207pub enum ErrorOutputType {
207- HumanReadable ( ColorConfig ) ,
208+ HumanReadable ( HumanReadableErrorType ) ,
208209 Json {
209210 /// Render the json in a human readable way (with indents and newlines)
210211 pretty : bool ,
211- /// The `rendered` field with the command line diagnostics include color codes
212- colorful_rendered : bool ,
212+ /// The way the `rendered` field is created
213+ json_rendered : HumanReadableErrorType ,
213214 } ,
214- Short ( ColorConfig ) ,
215215}
216216
217217impl Default for ErrorOutputType {
218218 fn default ( ) -> ErrorOutputType {
219- ErrorOutputType :: HumanReadable ( ColorConfig :: Auto )
219+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( ColorConfig :: Auto ) )
220220 }
221221}
222222
@@ -1350,8 +1350,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13501350 "print some statistics about AST and HIR" ) ,
13511351 always_encode_mir: bool = ( false , parse_bool, [ TRACKED ] ,
13521352 "encode MIR of all functions into the crate metadata" ) ,
1353- colorful_json : bool = ( false , parse_bool , [ UNTRACKED ] ,
1354- "encode color codes in the `rendered` field of json diagnostics" ) ,
1353+ json_rendered : Option < String > = ( None , parse_opt_string , [ UNTRACKED ] ,
1354+ "describes how to render the `rendered` field of json diagnostics" ) ,
13551355 unleash_the_miri_inside_of_you: bool = ( false , parse_bool, [ TRACKED ] ,
13561356 "take the breaks off const evaluation. NOTE: this is unsound" ) ,
13571357 osx_rpath_install_name: bool = ( false , parse_bool, [ TRACKED ] ,
@@ -1807,9 +1807,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
18071807 ) ,
18081808 opt:: opt(
18091809 "" ,
1810- "colorful- json" ,
1811- "Emit ansi color codes to the `rendered` field of json diagnostics" ,
1812- "TYPE " ,
1810+ "json-rendered " ,
1811+ "Choose `rendered` field of json diagnostics render scheme " ,
1812+ "plain|termcolor " ,
18131813 ) ,
18141814 opt:: opt_s(
18151815 "" ,
@@ -1951,22 +1951,32 @@ pub fn build_session_options_and_crate_config(
19511951 )
19521952 }
19531953
1954- let colorful_rendered = matches. opt_present ( "colorful-json" ) ;
1954+ let json_rendered = matches. opt_str ( "json-rendered" ) . and_then ( |s| match s. as_str ( ) {
1955+ "plain" => None ,
1956+ "termcolor" => Some ( HumanReadableErrorType :: Default ( ColorConfig :: Always ) ) ,
1957+ _ => early_error (
1958+ ErrorOutputType :: default ( ) ,
1959+ & format ! (
1960+ "argument for --json-rendered must be `plain` or `termcolor` (instead was `{}`)" ,
1961+ s,
1962+ ) ,
1963+ ) ,
1964+ } ) . unwrap_or ( HumanReadableErrorType :: Default ( ColorConfig :: Never ) ) ;
19551965
19561966 // We need the opts_present check because the driver will send us Matches
19571967 // with only stable options if no unstable options are used. Since error-format
19581968 // is unstable, it will not be present. We have to use opts_present not
19591969 // opt_present because the latter will panic.
19601970 let error_format = if matches. opts_present ( & [ "error-format" . to_owned ( ) ] ) {
19611971 match matches. opt_str ( "error-format" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
1962- Some ( "human" ) => ErrorOutputType :: HumanReadable ( color ) ,
1963- Some ( "json " ) => ErrorOutputType :: Json { pretty : false , colorful_rendered } ,
1964- Some ( "pretty- json" ) => ErrorOutputType :: Json { pretty : true , colorful_rendered } ,
1965- Some ( "short " ) => ErrorOutputType :: Short ( color ) ,
1966- None => ErrorOutputType :: HumanReadable ( color) ,
1972+ None |
1973+ Some ( "human " ) => ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color ) ) ,
1974+ Some ( "json" ) => ErrorOutputType :: Json { pretty : false , json_rendered } ,
1975+ Some ( "pretty-json " ) => ErrorOutputType :: Json { pretty : true , json_rendered } ,
1976+ Some ( "short" ) => ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Short ( color) ) ,
19671977
19681978 Some ( arg) => early_error (
1969- ErrorOutputType :: HumanReadable ( color) ,
1979+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) ) ,
19701980 & format ! (
19711981 "argument for --error-format must be `human`, `json` or \
19721982 `short` (instead was `{}`)",
@@ -1975,7 +1985,7 @@ pub fn build_session_options_and_crate_config(
19751985 ) ,
19761986 }
19771987 } else {
1978- ErrorOutputType :: HumanReadable ( color)
1988+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) )
19791989 } ;
19801990
19811991 let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
@@ -1988,12 +1998,12 @@ pub fn build_session_options_and_crate_config(
19881998 let mut debugging_opts = build_debugging_options ( matches, error_format) ;
19891999
19902000 if !debugging_opts. unstable_options {
1991- if colorful_rendered {
1992- early_error ( error_format, "--colorful- json=true is unstable" ) ;
2001+ if matches . opt_str ( "json-rendered" ) . is_some ( ) {
2002+ early_error ( error_format, "`-- json-rendered=x` is unstable" ) ;
19932003 }
1994- if let ErrorOutputType :: Json { pretty : true , .. } = error_format {
2004+ if let ErrorOutputType :: Json { pretty : true , json_rendered } = error_format {
19952005 early_error (
1996- ErrorOutputType :: Json { pretty : false , colorful_rendered : false } ,
2006+ ErrorOutputType :: Json { pretty : false , json_rendered } ,
19972007 "--error-format=pretty-json is unstable" ,
19982008 ) ;
19992009 }
@@ -2902,7 +2912,7 @@ mod tests {
29022912
29032913 const JSON : super :: ErrorOutputType = super :: ErrorOutputType :: Json {
29042914 pretty : false ,
2905- colorful_rendered : false ,
2915+ json_rendered : super :: HumanReadableErrorType :: Default ( super :: ColorConfig :: Never ) ,
29062916 } ;
29072917
29082918 // Reference
0 commit comments