Skip to content

Commit

Permalink
Make parse_json return JsonConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Mar 8, 2021
1 parent 3f2ca47 commit 2d52006
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions compiler/rustc_session/src/config.rs
Expand Up @@ -1251,11 +1251,18 @@ pub fn parse_color(matches: &getopts::Matches) -> ColorConfig {
}
}

/// Possible json config files
pub struct JsonConfig {
pub json_rendered: HumanReadableErrorType,
pub json_artifact_notifications: bool,
pub json_unused_externs: bool,
}

/// Parse the `--json` flag.
///
/// The first value returned is how to render JSON diagnostics, and the second
/// is whether or not artifact notifications are enabled.
pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool, bool) {
pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
let mut json_rendered: fn(ColorConfig) -> HumanReadableErrorType =
HumanReadableErrorType::Default;
let mut json_color = ColorConfig::Never;
Expand Down Expand Up @@ -1285,7 +1292,12 @@ pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool,
}
}
}
(json_rendered(json_color), json_artifact_notifications, json_unused_externs)

JsonConfig {
json_rendered: json_rendered(json_color),
json_artifact_notifications,
json_unused_externs,
}
}

/// Parses the `--error-format` flag.
Expand Down Expand Up @@ -1863,7 +1875,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {

let edition = parse_crate_edition(matches);

let (json_rendered, json_artifact_notifications, json_unused_externs) = parse_json(matches);
let JsonConfig { json_rendered, json_artifact_notifications, json_unused_externs } =
parse_json(matches);

let error_format = parse_error_format(matches, color, json_rendered);

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/config.rs
Expand Up @@ -323,7 +323,7 @@ impl Options {
}

let color = config::parse_color(&matches);
let (json_rendered, ..) = config::parse_json(&matches);
let config::JsonConfig { json_rendered, .. } = config::parse_json(&matches);
let error_format = config::parse_error_format(&matches, color, json_rendered);

let codegen_options = build_codegen_options(matches, error_format);
Expand Down

0 comments on commit 2d52006

Please sign in to comment.