Skip to content

Commit 0c4eaa5

Browse files
committed
Use default field values for ErrorOutputType
Remove manual `Default` impl from `config::ErrorOutputType`.
1 parent aae7a3c commit 0c4eaa5

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

Diff for: compiler/rustc_session/src/config.rs

+21-24
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,14 @@ impl OutputType {
655655
}
656656

657657
/// The type of diagnostics output to generate.
658-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
658+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
659659
pub enum ErrorOutputType {
660660
/// Output meant for the consumption of humans.
661-
HumanReadable(HumanReadableErrorType, ColorConfig),
661+
#[default]
662+
HumanReadable {
663+
kind: HumanReadableErrorType = HumanReadableErrorType::Default,
664+
color_config: ColorConfig = ColorConfig::Auto,
665+
},
662666
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
663667
Json {
664668
/// Render the JSON in a human readable way (with indents and newlines).
@@ -670,12 +674,6 @@ pub enum ErrorOutputType {
670674
},
671675
}
672676

673-
impl Default for ErrorOutputType {
674-
fn default() -> Self {
675-
Self::HumanReadable(HumanReadableErrorType::Default, ColorConfig::Auto)
676-
}
677-
}
678-
679677
#[derive(Clone, Hash, Debug)]
680678
pub enum ResolveDocLinks {
681679
/// Do not resolve doc links.
@@ -1790,7 +1788,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
17901788
pub fn parse_error_format(
17911789
early_dcx: &mut EarlyDiagCtxt,
17921790
matches: &getopts::Matches,
1793-
color: ColorConfig,
1791+
color_config: ColorConfig,
17941792
json_color: ColorConfig,
17951793
json_rendered: HumanReadableErrorType,
17961794
) -> ErrorOutputType {
@@ -1800,35 +1798,34 @@ pub fn parse_error_format(
18001798
// `opt_present` because the latter will panic.
18011799
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
18021800
match matches.opt_str("error-format").as_deref() {
1803-
None | Some("human") => {
1804-
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
1805-
}
1806-
Some("human-annotate-rs") => {
1807-
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet, color)
1808-
}
1801+
None | Some("human") => ErrorOutputType::HumanReadable { color_config, .. },
1802+
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
1803+
kind: HumanReadableErrorType::AnnotateSnippet,
1804+
color_config,
1805+
},
18091806
Some("json") => {
18101807
ErrorOutputType::Json { pretty: false, json_rendered, color_config: json_color }
18111808
}
18121809
Some("pretty-json") => {
18131810
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
18141811
}
1815-
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short, color),
1816-
Some("human-unicode") => {
1817-
ErrorOutputType::HumanReadable(HumanReadableErrorType::Unicode, color)
1812+
Some("short") => {
1813+
ErrorOutputType::HumanReadable { kind: HumanReadableErrorType::Short, color_config }
18181814
}
1815+
Some("human-unicode") => ErrorOutputType::HumanReadable {
1816+
kind: HumanReadableErrorType::Unicode,
1817+
color_config,
1818+
},
18191819
Some(arg) => {
1820-
early_dcx.set_error_format(ErrorOutputType::HumanReadable(
1821-
HumanReadableErrorType::Default,
1822-
color,
1823-
));
1820+
early_dcx.set_error_format(ErrorOutputType::HumanReadable { color_config, .. });
18241821
early_dcx.early_fatal(format!(
18251822
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
18261823
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
18271824
))
18281825
}
18291826
}
18301827
} else {
1831-
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
1828+
ErrorOutputType::HumanReadable { color_config, .. }
18321829
};
18331830

18341831
match error_format {
@@ -1883,7 +1880,7 @@ fn check_error_format_stability(
18831880
}
18841881
let format = match format {
18851882
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
1886-
ErrorOutputType::HumanReadable(format, _) => match format {
1883+
ErrorOutputType::HumanReadable { kind, .. } => match kind {
18871884
HumanReadableErrorType::AnnotateSnippet => "human-annotate-rs",
18881885
HumanReadableErrorType::Unicode => "human-unicode",
18891886
_ => return,

Diff for: compiler/rustc_session/src/session.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ fn default_emitter(
913913
let source_map = if sopts.unstable_opts.link_only { None } else { Some(source_map) };
914914

915915
match sopts.error_format {
916-
config::ErrorOutputType::HumanReadable(kind, color_config) => {
916+
config::ErrorOutputType::HumanReadable { kind, color_config } => {
917917
let short = kind.short();
918918

919919
if let HumanReadableErrorType::AnnotateSnippet = kind {
@@ -1430,7 +1430,7 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
14301430
let fallback_bundle =
14311431
fallback_fluent_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false);
14321432
let emitter: Box<DynEmitter> = match output {
1433-
config::ErrorOutputType::HumanReadable(kind, color_config) => {
1433+
config::ErrorOutputType::HumanReadable { kind, color_config } => {
14341434
let short = kind.short();
14351435
Box::new(
14361436
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)

Diff for: src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub(crate) fn new_dcx(
153153
false,
154154
);
155155
let emitter: Box<DynEmitter> = match error_format {
156-
ErrorOutputType::HumanReadable(kind, color_config) => {
156+
ErrorOutputType::HumanReadable { kind, color_config } => {
157157
let short = kind.short();
158158
Box::new(
159159
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)

Diff for: src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ fn run_test(
580580
path_for_rustdoc.to_str().expect("target path must be valid unicode")
581581
}
582582
});
583-
if let ErrorOutputType::HumanReadable(kind, color_config) = rustdoc_options.error_format {
583+
if let ErrorOutputType::HumanReadable { kind, color_config } = rustdoc_options.error_format {
584584
let short = kind.short();
585585
let unicode = kind == HumanReadableErrorType::Unicode;
586586

0 commit comments

Comments
 (0)