@@ -757,7 +757,7 @@ impl Default for Options {
757757 real_rust_source_base_dir : None ,
758758 edition : DEFAULT_EDITION ,
759759 json_artifact_notifications : false ,
760- json_unused_externs : false ,
760+ json_unused_externs : JsonUnusedExterns :: No ,
761761 json_future_incompat : false ,
762762 pretty : None ,
763763 working_dir : RealFileName :: LocalPath ( std:: env:: current_dir ( ) . unwrap ( ) ) ,
@@ -1493,10 +1493,37 @@ pub fn parse_color(matches: &getopts::Matches) -> ColorConfig {
14931493pub struct JsonConfig {
14941494 pub json_rendered : HumanReadableErrorType ,
14951495 pub json_artifact_notifications : bool ,
1496- pub json_unused_externs : bool ,
1496+ pub json_unused_externs : JsonUnusedExterns ,
14971497 pub json_future_incompat : bool ,
14981498}
14991499
1500+ /// Report unused externs in event stream
1501+ #[ derive( Copy , Clone ) ]
1502+ pub enum JsonUnusedExterns {
1503+ /// Do not
1504+ No ,
1505+ /// Report, but do not exit with failure status for deny/forbid
1506+ Silent ,
1507+ /// Report, and also exit with failure status for deny/forbid
1508+ Loud ,
1509+ }
1510+
1511+ impl JsonUnusedExterns {
1512+ pub fn is_enabled ( & self ) -> bool {
1513+ match self {
1514+ JsonUnusedExterns :: No => false ,
1515+ JsonUnusedExterns :: Loud | JsonUnusedExterns :: Silent => true ,
1516+ }
1517+ }
1518+
1519+ pub fn is_loud ( & self ) -> bool {
1520+ match self {
1521+ JsonUnusedExterns :: No | JsonUnusedExterns :: Silent => false ,
1522+ JsonUnusedExterns :: Loud => true ,
1523+ }
1524+ }
1525+ }
1526+
15001527/// Parse the `--json` flag.
15011528///
15021529/// The first value returned is how to render JSON diagnostics, and the second
@@ -1506,7 +1533,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
15061533 HumanReadableErrorType :: Default ;
15071534 let mut json_color = ColorConfig :: Never ;
15081535 let mut json_artifact_notifications = false ;
1509- let mut json_unused_externs = false ;
1536+ let mut json_unused_externs = JsonUnusedExterns :: No ;
15101537 let mut json_future_incompat = false ;
15111538 for option in matches. opt_strs ( "json" ) {
15121539 // For now conservatively forbid `--color` with `--json` since `--json`
@@ -1524,7 +1551,8 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
15241551 "diagnostic-short" => json_rendered = HumanReadableErrorType :: Short ,
15251552 "diagnostic-rendered-ansi" => json_color = ColorConfig :: Always ,
15261553 "artifacts" => json_artifact_notifications = true ,
1527- "unused-externs" => json_unused_externs = true ,
1554+ "unused-externs" => json_unused_externs = JsonUnusedExterns :: Loud ,
1555+ "unused-externs-silent" => json_unused_externs = JsonUnusedExterns :: Silent ,
15281556 "future-incompat" => json_future_incompat = true ,
15291557 s => early_error (
15301558 ErrorOutputType :: default ( ) ,
@@ -2224,7 +2252,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
22242252
22252253 check_debug_option_stability ( & debugging_opts, error_format, json_rendered) ;
22262254
2227- if !debugging_opts. unstable_options && json_unused_externs {
2255+ if !debugging_opts. unstable_options && json_unused_externs. is_enabled ( ) {
22282256 early_error (
22292257 error_format,
22302258 "the `-Z unstable-options` flag must also be passed to enable \
0 commit comments