@@ -19,6 +19,7 @@ use syntax::parse::token;
19
19
use syntax:: parse;
20
20
use syntax:: symbol:: Symbol ;
21
21
use syntax:: feature_gate:: UnstableFeatures ;
22
+ use errors:: emitter:: HumanReadableErrorType ;
22
23
23
24
use errors:: { ColorConfig , FatalError , Handler } ;
24
25
@@ -219,14 +220,18 @@ impl OutputType {
219
220
220
221
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
221
222
pub enum ErrorOutputType {
222
- HumanReadable ( ColorConfig ) ,
223
- Json ( bool ) ,
224
- Short ( ColorConfig ) ,
223
+ HumanReadable ( HumanReadableErrorType ) ,
224
+ Json {
225
+ /// Render the json in a human readable way (with indents and newlines)
226
+ pretty : bool ,
227
+ /// The way the `rendered` field is created
228
+ json_rendered : HumanReadableErrorType ,
229
+ } ,
225
230
}
226
231
227
232
impl Default for ErrorOutputType {
228
233
fn default ( ) -> ErrorOutputType {
229
- ErrorOutputType :: HumanReadable ( ColorConfig :: Auto )
234
+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( ColorConfig :: Auto ) )
230
235
}
231
236
}
232
237
@@ -1372,6 +1377,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
1372
1377
"print some statistics about AST and HIR" ) ,
1373
1378
always_encode_mir: bool = ( false , parse_bool, [ TRACKED ] ,
1374
1379
"encode MIR of all functions into the crate metadata" ) ,
1380
+ json_rendered: Option <String > = ( None , parse_opt_string, [ UNTRACKED ] ,
1381
+ "describes how to render the `rendered` field of json diagnostics" ) ,
1375
1382
unleash_the_miri_inside_of_you: bool = ( false , parse_bool, [ TRACKED ] ,
1376
1383
"take the breaks off const evaluation. NOTE: this is unsound" ) ,
1377
1384
osx_rpath_install_name: bool = ( false , parse_bool, [ TRACKED ] ,
@@ -1825,6 +1832,12 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
1825
1832
"How errors and other messages are produced" ,
1826
1833
"human|json|short" ,
1827
1834
) ,
1835
+ opt:: opt(
1836
+ "" ,
1837
+ "json-rendered" ,
1838
+ "Choose `rendered` field of json diagnostics render scheme" ,
1839
+ "plain|termcolor" ,
1840
+ ) ,
1828
1841
opt:: opt_s(
1829
1842
"" ,
1830
1843
"color" ,
@@ -1965,21 +1978,32 @@ pub fn build_session_options_and_crate_config(
1965
1978
)
1966
1979
}
1967
1980
1981
+ let json_rendered = matches. opt_str ( "json-rendered" ) . and_then ( |s| match s. as_str ( ) {
1982
+ "plain" => None ,
1983
+ "termcolor" => Some ( HumanReadableErrorType :: Default ( ColorConfig :: Always ) ) ,
1984
+ _ => early_error (
1985
+ ErrorOutputType :: default ( ) ,
1986
+ & format ! (
1987
+ "argument for --json-rendered must be `plain` or `termcolor` (instead was `{}`)" ,
1988
+ s,
1989
+ ) ,
1990
+ ) ,
1991
+ } ) . unwrap_or ( HumanReadableErrorType :: Default ( ColorConfig :: Never ) ) ;
1968
1992
1969
1993
// We need the opts_present check because the driver will send us Matches
1970
1994
// with only stable options if no unstable options are used. Since error-format
1971
1995
// is unstable, it will not be present. We have to use opts_present not
1972
1996
// opt_present because the latter will panic.
1973
1997
let error_format = if matches. opts_present ( & [ "error-format" . to_owned ( ) ] ) {
1974
1998
match matches. opt_str ( "error-format" ) . as_ref ( ) . map ( |s| & s[ ..] ) {
1975
- Some ( "human" ) => ErrorOutputType :: HumanReadable ( color ) ,
1976
- Some ( "json " ) => ErrorOutputType :: Json ( false ) ,
1977
- Some ( "pretty- json" ) => ErrorOutputType :: Json ( true ) ,
1978
- Some ( "short " ) => ErrorOutputType :: Short ( color ) ,
1979
- None => ErrorOutputType :: HumanReadable ( color) ,
1999
+ None |
2000
+ Some ( "human " ) => ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color ) ) ,
2001
+ Some ( "json" ) => ErrorOutputType :: Json { pretty : false , json_rendered } ,
2002
+ Some ( "pretty-json " ) => ErrorOutputType :: Json { pretty : true , json_rendered } ,
2003
+ Some ( "short" ) => ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Short ( color) ) ,
1980
2004
1981
2005
Some ( arg) => early_error (
1982
- ErrorOutputType :: HumanReadable ( color) ,
2006
+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) ) ,
1983
2007
& format ! (
1984
2008
"argument for --error-format must be `human`, `json` or \
1985
2009
`short` (instead was `{}`)",
@@ -1988,7 +2012,7 @@ pub fn build_session_options_and_crate_config(
1988
2012
) ,
1989
2013
}
1990
2014
} else {
1991
- ErrorOutputType :: HumanReadable ( color)
2015
+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) )
1992
2016
} ;
1993
2017
1994
2018
let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
@@ -2000,11 +2024,16 @@ pub fn build_session_options_and_crate_config(
2000
2024
2001
2025
let mut debugging_opts = build_debugging_options ( matches, error_format) ;
2002
2026
2003
- if !debugging_opts. unstable_options && error_format == ErrorOutputType :: Json ( true ) {
2004
- early_error (
2005
- ErrorOutputType :: Json ( false ) ,
2006
- "--error-format=pretty-json is unstable" ,
2007
- ) ;
2027
+ if !debugging_opts. unstable_options {
2028
+ if matches. opt_str ( "json-rendered" ) . is_some ( ) {
2029
+ early_error ( error_format, "`--json-rendered=x` is unstable" ) ;
2030
+ }
2031
+ if let ErrorOutputType :: Json { pretty : true , json_rendered } = error_format {
2032
+ early_error (
2033
+ ErrorOutputType :: Json { pretty : false , json_rendered } ,
2034
+ "--error-format=pretty-json is unstable" ,
2035
+ ) ;
2036
+ }
2008
2037
}
2009
2038
2010
2039
if debugging_opts. pgo_gen . enabled ( ) && !debugging_opts. pgo_use . is_empty ( ) {
@@ -2928,50 +2957,55 @@ mod tests {
2928
2957
let mut v3 = Options :: default ( ) ;
2929
2958
let mut v4 = Options :: default ( ) ;
2930
2959
2960
+ const JSON : super :: ErrorOutputType = super :: ErrorOutputType :: Json {
2961
+ pretty : false ,
2962
+ json_rendered : super :: HumanReadableErrorType :: Default ( super :: ColorConfig :: Never ) ,
2963
+ } ;
2964
+
2931
2965
// Reference
2932
2966
v1. search_paths
2933
- . push ( SearchPath :: from_cli_opt ( "native=abc" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2967
+ . push ( SearchPath :: from_cli_opt ( "native=abc" , JSON ) ) ;
2934
2968
v1. search_paths
2935
- . push ( SearchPath :: from_cli_opt ( "crate=def" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2969
+ . push ( SearchPath :: from_cli_opt ( "crate=def" , JSON ) ) ;
2936
2970
v1. search_paths
2937
- . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2971
+ . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , JSON ) ) ;
2938
2972
v1. search_paths
2939
- . push ( SearchPath :: from_cli_opt ( "framework=jkl" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2973
+ . push ( SearchPath :: from_cli_opt ( "framework=jkl" , JSON ) ) ;
2940
2974
v1. search_paths
2941
- . push ( SearchPath :: from_cli_opt ( "all=mno" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2975
+ . push ( SearchPath :: from_cli_opt ( "all=mno" , JSON ) ) ;
2942
2976
2943
2977
v2. search_paths
2944
- . push ( SearchPath :: from_cli_opt ( "native=abc" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2978
+ . push ( SearchPath :: from_cli_opt ( "native=abc" , JSON ) ) ;
2945
2979
v2. search_paths
2946
- . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2980
+ . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , JSON ) ) ;
2947
2981
v2. search_paths
2948
- . push ( SearchPath :: from_cli_opt ( "crate=def" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2982
+ . push ( SearchPath :: from_cli_opt ( "crate=def" , JSON ) ) ;
2949
2983
v2. search_paths
2950
- . push ( SearchPath :: from_cli_opt ( "framework=jkl" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2984
+ . push ( SearchPath :: from_cli_opt ( "framework=jkl" , JSON ) ) ;
2951
2985
v2. search_paths
2952
- . push ( SearchPath :: from_cli_opt ( "all=mno" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2986
+ . push ( SearchPath :: from_cli_opt ( "all=mno" , JSON ) ) ;
2953
2987
2954
2988
v3. search_paths
2955
- . push ( SearchPath :: from_cli_opt ( "crate=def" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2989
+ . push ( SearchPath :: from_cli_opt ( "crate=def" , JSON ) ) ;
2956
2990
v3. search_paths
2957
- . push ( SearchPath :: from_cli_opt ( "framework=jkl" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2991
+ . push ( SearchPath :: from_cli_opt ( "framework=jkl" , JSON ) ) ;
2958
2992
v3. search_paths
2959
- . push ( SearchPath :: from_cli_opt ( "native=abc" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2993
+ . push ( SearchPath :: from_cli_opt ( "native=abc" , JSON ) ) ;
2960
2994
v3. search_paths
2961
- . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2995
+ . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , JSON ) ) ;
2962
2996
v3. search_paths
2963
- . push ( SearchPath :: from_cli_opt ( "all=mno" , super :: ErrorOutputType :: Json ( false ) ) ) ;
2997
+ . push ( SearchPath :: from_cli_opt ( "all=mno" , JSON ) ) ;
2964
2998
2965
2999
v4. search_paths
2966
- . push ( SearchPath :: from_cli_opt ( "all=mno" , super :: ErrorOutputType :: Json ( false ) ) ) ;
3000
+ . push ( SearchPath :: from_cli_opt ( "all=mno" , JSON ) ) ;
2967
3001
v4. search_paths
2968
- . push ( SearchPath :: from_cli_opt ( "native=abc" , super :: ErrorOutputType :: Json ( false ) ) ) ;
3002
+ . push ( SearchPath :: from_cli_opt ( "native=abc" , JSON ) ) ;
2969
3003
v4. search_paths
2970
- . push ( SearchPath :: from_cli_opt ( "crate=def" , super :: ErrorOutputType :: Json ( false ) ) ) ;
3004
+ . push ( SearchPath :: from_cli_opt ( "crate=def" , JSON ) ) ;
2971
3005
v4. search_paths
2972
- . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , super :: ErrorOutputType :: Json ( false ) ) ) ;
3006
+ . push ( SearchPath :: from_cli_opt ( "dependency=ghi" , JSON ) ) ;
2973
3007
v4. search_paths
2974
- . push ( SearchPath :: from_cli_opt ( "framework=jkl" , super :: ErrorOutputType :: Json ( false ) ) ) ;
3008
+ . push ( SearchPath :: from_cli_opt ( "framework=jkl" , JSON ) ) ;
2975
3009
2976
3010
assert ! ( v1. dep_tracking_hash( ) == v2. dep_tracking_hash( ) ) ;
2977
3011
assert ! ( v1. dep_tracking_hash( ) == v3. dep_tracking_hash( ) ) ;
0 commit comments