Gate the printing on --json=unused-externs

This commit is contained in:
est31 2020-06-30 20:17:07 +02:00
parent aef1e35edc
commit 3f2ca47a79
4 changed files with 22 additions and 6 deletions

View file

@ -931,8 +931,9 @@ impl<'a> CrateLoader<'a> {
diag, diag,
); );
} }
// FIXME: add gating if self.sess.opts.json_unused_externs {
self.sess.parse_sess.span_diagnostic.emit_unused_externs(&unused_externs); self.sess.parse_sess.span_diagnostic.emit_unused_externs(&unused_externs);
}
} }
pub fn postprocess(&mut self, krate: &ast::Crate) { pub fn postprocess(&mut self, krate: &ast::Crate) {

View file

@ -734,6 +734,7 @@ impl Default for Options {
remap_path_prefix: Vec::new(), remap_path_prefix: Vec::new(),
edition: DEFAULT_EDITION, edition: DEFAULT_EDITION,
json_artifact_notifications: false, json_artifact_notifications: false,
json_unused_externs: false,
pretty: None, pretty: None,
} }
} }
@ -1254,11 +1255,12 @@ pub fn parse_color(matches: &getopts::Matches) -> ColorConfig {
/// ///
/// The first value returned is how to render JSON diagnostics, and the second /// The first value returned is how to render JSON diagnostics, and the second
/// is whether or not artifact notifications are enabled. /// is whether or not artifact notifications are enabled.
pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool) { pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool, bool) {
let mut json_rendered: fn(ColorConfig) -> HumanReadableErrorType = let mut json_rendered: fn(ColorConfig) -> HumanReadableErrorType =
HumanReadableErrorType::Default; HumanReadableErrorType::Default;
let mut json_color = ColorConfig::Never; let mut json_color = ColorConfig::Never;
let mut json_artifact_notifications = false; let mut json_artifact_notifications = false;
let mut json_unused_externs = false;
for option in matches.opt_strs("json") { for option in matches.opt_strs("json") {
// For now conservatively forbid `--color` with `--json` since `--json` // For now conservatively forbid `--color` with `--json` since `--json`
// won't actually be emitting any colors and anything colorized is // won't actually be emitting any colors and anything colorized is
@ -1275,6 +1277,7 @@ pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool)
"diagnostic-short" => json_rendered = HumanReadableErrorType::Short, "diagnostic-short" => json_rendered = HumanReadableErrorType::Short,
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always, "diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
"artifacts" => json_artifact_notifications = true, "artifacts" => json_artifact_notifications = true,
"unused-externs" => json_unused_externs = true,
s => early_error( s => early_error(
ErrorOutputType::default(), ErrorOutputType::default(),
&format!("unknown `--json` option `{}`", s), &format!("unknown `--json` option `{}`", s),
@ -1282,7 +1285,7 @@ pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool)
} }
} }
} }
(json_rendered(json_color), json_artifact_notifications) (json_rendered(json_color), json_artifact_notifications, json_unused_externs)
} }
/// Parses the `--error-format` flag. /// Parses the `--error-format` flag.
@ -1860,7 +1863,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let edition = parse_crate_edition(matches); let edition = parse_crate_edition(matches);
let (json_rendered, json_artifact_notifications) = parse_json(matches); let (json_rendered, json_artifact_notifications, json_unused_externs) = parse_json(matches);
let error_format = parse_error_format(matches, color, json_rendered); let error_format = parse_error_format(matches, color, json_rendered);
@ -1873,6 +1876,14 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut debugging_opts = build_debugging_options(matches, error_format); let mut debugging_opts = build_debugging_options(matches, error_format);
check_debug_option_stability(&debugging_opts, error_format, json_rendered); check_debug_option_stability(&debugging_opts, error_format, json_rendered);
if !debugging_opts.unstable_options && json_unused_externs {
early_error(
error_format,
"the `-Z unstable-options` flag must also be passed to enable \
the flag `--json=unused-externs`",
);
}
let output_types = parse_output_types(&debugging_opts, matches, error_format); let output_types = parse_output_types(&debugging_opts, matches, error_format);
let mut cg = build_codegen_options(matches, error_format); let mut cg = build_codegen_options(matches, error_format);
@ -2050,6 +2061,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
remap_path_prefix, remap_path_prefix,
edition, edition,
json_artifact_notifications, json_artifact_notifications,
json_unused_externs,
pretty, pretty,
} }
} }

View file

@ -147,6 +147,9 @@ top_level_options!(
// by the compiler. // by the compiler.
json_artifact_notifications: bool [TRACKED], json_artifact_notifications: bool [TRACKED],
// `true` if we're emitting a JSON blob containing the unused externs
json_unused_externs: bool [UNTRACKED],
pretty: Option<PpMode> [UNTRACKED], pretty: Option<PpMode> [UNTRACKED],
} }
); );

View file

@ -323,7 +323,7 @@ impl Options {
} }
let color = config::parse_color(&matches); let color = config::parse_color(&matches);
let (json_rendered, _artifacts) = config::parse_json(&matches); let (json_rendered, ..) = config::parse_json(&matches);
let error_format = config::parse_error_format(&matches, color, json_rendered); let error_format = config::parse_error_format(&matches, color, json_rendered);
let codegen_options = build_codegen_options(matches, error_format); let codegen_options = build_codegen_options(matches, error_format);