@@ -734,6 +734,7 @@ impl Default for Options {
734
734
remap_path_prefix : Vec :: new ( ) ,
735
735
edition : DEFAULT_EDITION ,
736
736
json_artifact_notifications : false ,
737
+ json_unused_externs : false ,
737
738
pretty : None ,
738
739
}
739
740
}
@@ -1254,11 +1255,12 @@ pub fn parse_color(matches: &getopts::Matches) -> ColorConfig {
1254
1255
///
1255
1256
/// The first value returned is how to render JSON diagnostics, and the second
1256
1257
/// is whether or not artifact notifications are enabled.
1257
- pub fn parse_json ( matches : & getopts:: Matches ) -> ( HumanReadableErrorType , bool ) {
1258
+ pub fn parse_json ( matches : & getopts:: Matches ) -> ( HumanReadableErrorType , bool , bool ) {
1258
1259
let mut json_rendered: fn ( ColorConfig ) -> HumanReadableErrorType =
1259
1260
HumanReadableErrorType :: Default ;
1260
1261
let mut json_color = ColorConfig :: Never ;
1261
1262
let mut json_artifact_notifications = false ;
1263
+ let mut json_unused_externs = false ;
1262
1264
for option in matches. opt_strs ( "json" ) {
1263
1265
// For now conservatively forbid `--color` with `--json` since `--json`
1264
1266
// won't actually be emitting any colors and anything colorized is
@@ -1275,14 +1277,15 @@ pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool)
1275
1277
"diagnostic-short" => json_rendered = HumanReadableErrorType :: Short ,
1276
1278
"diagnostic-rendered-ansi" => json_color = ColorConfig :: Always ,
1277
1279
"artifacts" => json_artifact_notifications = true ,
1280
+ "unused-externs" => json_unused_externs = true ,
1278
1281
s => early_error (
1279
1282
ErrorOutputType :: default ( ) ,
1280
1283
& format ! ( "unknown `--json` option `{}`" , s) ,
1281
1284
) ,
1282
1285
}
1283
1286
}
1284
1287
}
1285
- ( json_rendered ( json_color) , json_artifact_notifications)
1288
+ ( json_rendered ( json_color) , json_artifact_notifications, json_unused_externs )
1286
1289
}
1287
1290
1288
1291
/// Parses the `--error-format` flag.
@@ -1860,7 +1863,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
1860
1863
1861
1864
let edition = parse_crate_edition ( matches) ;
1862
1865
1863
- let ( json_rendered, json_artifact_notifications) = parse_json ( matches) ;
1866
+ let ( json_rendered, json_artifact_notifications, json_unused_externs ) = parse_json ( matches) ;
1864
1867
1865
1868
let error_format = parse_error_format ( matches, color, json_rendered) ;
1866
1869
@@ -1873,6 +1876,14 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
1873
1876
let mut debugging_opts = build_debugging_options ( matches, error_format) ;
1874
1877
check_debug_option_stability ( & debugging_opts, error_format, json_rendered) ;
1875
1878
1879
+ if !debugging_opts. unstable_options && json_unused_externs {
1880
+ early_error (
1881
+ error_format,
1882
+ "the `-Z unstable-options` flag must also be passed to enable \
1883
+ the flag `--json=unused-externs`",
1884
+ ) ;
1885
+ }
1886
+
1876
1887
let output_types = parse_output_types ( & debugging_opts, matches, error_format) ;
1877
1888
1878
1889
let mut cg = build_codegen_options ( matches, error_format) ;
@@ -2050,6 +2061,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
2050
2061
remap_path_prefix,
2051
2062
edition,
2052
2063
json_artifact_notifications,
2064
+ json_unused_externs,
2053
2065
pretty,
2054
2066
}
2055
2067
}
0 commit comments