Skip to content

Commit c8b090c

Browse files
committed
Auto merge of #11358 - hi-rustin:rustin-patch-error-msg, r=weihanglo
Extract `two_kinds_of_msg_format_err` message to de-duplicate it ### What does this PR try to resolve? Extract `two_kinds_of_msg_format_err` message to de-duplicate it. I guess this would be helpful for changing this message. ### Additional information Just found it when I read the code. So if you prefer the former code style, please feel free to close my PR.
2 parents 9865dde + 9060360 commit c8b090c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/cargo/util/command_prelude.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,25 +469,26 @@ pub trait ArgMatchesExt {
469469
ansi: false,
470470
render_diagnostics: false,
471471
};
472+
let two_kinds_of_msg_format_err = "cannot specify two kinds of `message-format` arguments";
472473
for fmt in self._values_of("message-format") {
473474
for fmt in fmt.split(',') {
474475
let fmt = fmt.to_ascii_lowercase();
475476
match fmt.as_str() {
476477
"json" => {
477478
if message_format.is_some() {
478-
bail!("cannot specify two kinds of `message-format` arguments");
479+
bail!(two_kinds_of_msg_format_err);
479480
}
480481
message_format = Some(default_json);
481482
}
482483
"human" => {
483484
if message_format.is_some() {
484-
bail!("cannot specify two kinds of `message-format` arguments");
485+
bail!(two_kinds_of_msg_format_err);
485486
}
486487
message_format = Some(MessageFormat::Human);
487488
}
488489
"short" => {
489490
if message_format.is_some() {
490-
bail!("cannot specify two kinds of `message-format` arguments");
491+
bail!(two_kinds_of_msg_format_err);
491492
}
492493
message_format = Some(MessageFormat::Short);
493494
}
@@ -499,7 +500,7 @@ pub trait ArgMatchesExt {
499500
Some(MessageFormat::Json {
500501
render_diagnostics, ..
501502
}) => *render_diagnostics = true,
502-
_ => bail!("cannot specify two kinds of `message-format` arguments"),
503+
_ => bail!(two_kinds_of_msg_format_err),
503504
}
504505
}
505506
"json-diagnostic-short" => {
@@ -508,7 +509,7 @@ pub trait ArgMatchesExt {
508509
}
509510
match &mut message_format {
510511
Some(MessageFormat::Json { short, .. }) => *short = true,
511-
_ => bail!("cannot specify two kinds of `message-format` arguments"),
512+
_ => bail!(two_kinds_of_msg_format_err),
512513
}
513514
}
514515
"json-diagnostic-rendered-ansi" => {
@@ -517,7 +518,7 @@ pub trait ArgMatchesExt {
517518
}
518519
match &mut message_format {
519520
Some(MessageFormat::Json { ansi, .. }) => *ansi = true,
520-
_ => bail!("cannot specify two kinds of `message-format` arguments"),
521+
_ => bail!(two_kinds_of_msg_format_err),
521522
}
522523
}
523524
s => bail!("invalid message format specifier: `{}`", s),

0 commit comments

Comments
 (0)