@@ -757,7 +757,7 @@ impl Default for Options {
757
757
real_rust_source_base_dir : None ,
758
758
edition : DEFAULT_EDITION ,
759
759
json_artifact_notifications : false ,
760
- json_unused_externs : false ,
760
+ json_unused_externs : JsonUnusedExterns :: No ,
761
761
json_future_incompat : false ,
762
762
pretty : None ,
763
763
working_dir : RealFileName :: LocalPath ( std:: env:: current_dir ( ) . unwrap ( ) ) ,
@@ -1493,10 +1493,37 @@ pub fn parse_color(matches: &getopts::Matches) -> ColorConfig {
1493
1493
pub struct JsonConfig {
1494
1494
pub json_rendered : HumanReadableErrorType ,
1495
1495
pub json_artifact_notifications : bool ,
1496
- pub json_unused_externs : bool ,
1496
+ pub json_unused_externs : JsonUnusedExterns ,
1497
1497
pub json_future_incompat : bool ,
1498
1498
}
1499
1499
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
+
1500
1527
/// Parse the `--json` flag.
1501
1528
///
1502
1529
/// 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 {
1506
1533
HumanReadableErrorType :: Default ;
1507
1534
let mut json_color = ColorConfig :: Never ;
1508
1535
let mut json_artifact_notifications = false ;
1509
- let mut json_unused_externs = false ;
1536
+ let mut json_unused_externs = JsonUnusedExterns :: No ;
1510
1537
let mut json_future_incompat = false ;
1511
1538
for option in matches. opt_strs ( "json" ) {
1512
1539
// For now conservatively forbid `--color` with `--json` since `--json`
@@ -1524,7 +1551,8 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
1524
1551
"diagnostic-short" => json_rendered = HumanReadableErrorType :: Short ,
1525
1552
"diagnostic-rendered-ansi" => json_color = ColorConfig :: Always ,
1526
1553
"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 ,
1528
1556
"future-incompat" => json_future_incompat = true ,
1529
1557
s => early_error (
1530
1558
ErrorOutputType :: default ( ) ,
@@ -2224,7 +2252,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
2224
2252
2225
2253
check_debug_option_stability ( & debugging_opts, error_format, json_rendered) ;
2226
2254
2227
- if !debugging_opts. unstable_options && json_unused_externs {
2255
+ if !debugging_opts. unstable_options && json_unused_externs. is_enabled ( ) {
2228
2256
early_error (
2229
2257
error_format,
2230
2258
"the `-Z unstable-options` flag must also be passed to enable \
0 commit comments