@@ -734,6 +734,7 @@ impl Default for Options {
734734 remap_path_prefix : Vec :: new ( ) ,
735735 edition : DEFAULT_EDITION ,
736736 json_artifact_notifications : false ,
737+ json_unused_externs : false ,
737738 pretty : None ,
738739 }
739740 }
@@ -1254,11 +1255,12 @@ pub fn parse_color(matches: &getopts::Matches) -> ColorConfig {
12541255///
12551256/// The first value returned is how to render JSON diagnostics, and the second
12561257/// 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 ) {
12581259 let mut json_rendered: fn ( ColorConfig ) -> HumanReadableErrorType =
12591260 HumanReadableErrorType :: Default ;
12601261 let mut json_color = ColorConfig :: Never ;
12611262 let mut json_artifact_notifications = false ;
1263+ let mut json_unused_externs = false ;
12621264 for option in matches. opt_strs ( "json" ) {
12631265 // For now conservatively forbid `--color` with `--json` since `--json`
12641266 // won't actually be emitting any colors and anything colorized is
@@ -1275,14 +1277,15 @@ pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool)
12751277 "diagnostic-short" => json_rendered = HumanReadableErrorType :: Short ,
12761278 "diagnostic-rendered-ansi" => json_color = ColorConfig :: Always ,
12771279 "artifacts" => json_artifact_notifications = true ,
1280+ "unused-externs" => json_unused_externs = true ,
12781281 s => early_error (
12791282 ErrorOutputType :: default ( ) ,
12801283 & format ! ( "unknown `--json` option `{}`" , s) ,
12811284 ) ,
12821285 }
12831286 }
12841287 }
1285- ( json_rendered ( json_color) , json_artifact_notifications)
1288+ ( json_rendered ( json_color) , json_artifact_notifications, json_unused_externs )
12861289}
12871290
12881291/// Parses the `--error-format` flag.
@@ -1860,7 +1863,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
18601863
18611864 let edition = parse_crate_edition ( matches) ;
18621865
1863- let ( json_rendered, json_artifact_notifications) = parse_json ( matches) ;
1866+ let ( json_rendered, json_artifact_notifications, json_unused_externs ) = parse_json ( matches) ;
18641867
18651868 let error_format = parse_error_format ( matches, color, json_rendered) ;
18661869
@@ -1873,6 +1876,14 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
18731876 let mut debugging_opts = build_debugging_options ( matches, error_format) ;
18741877 check_debug_option_stability ( & debugging_opts, error_format, json_rendered) ;
18751878
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+
18761887 let output_types = parse_output_types ( & debugging_opts, matches, error_format) ;
18771888
18781889 let mut cg = build_codegen_options ( matches, error_format) ;
@@ -2050,6 +2061,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
20502061 remap_path_prefix,
20512062 edition,
20522063 json_artifact_notifications,
2064+ json_unused_externs,
20532065 pretty,
20542066 }
20552067}
0 commit comments