Skip to content

Commit 972ccba

Browse files
committed
Auto merge of #5879 - dwijnand:short-errors, r=alexcrichton
Add support for rustc's --error-format short Running a local build of this branch on some broken code shows this kind of output: 18:42:29 $ dcargo check --message-format=short --tests Checking bufstream v0.1.3 Checking cargo v0.30.0 (file:///d/cargo) tests/testsuite/config.rs:298:9: error[E0308]: mismatched types tests/testsuite/config.rs:307:9: error[E0308]: mismatched types tests/testsuite/config.rs:363:9: error[E0308]: mismatched types tests/testsuite/config.rs:367:9: error[E0308]: mismatched types tests/testsuite/config.rs:371:9: error[E0308]: mismatched types tests/testsuite/config.rs:375:9: error[E0308]: mismatched types tests/testsuite/config.rs:382:9: error[E0308]: mismatched types tests/testsuite/config.rs:386:9: error[E0308]: mismatched types tests/testsuite/config.rs:400:9: error[E0308]: mismatched types tests/testsuite/config.rs:428:9: error[E0308]: mismatched types tests/testsuite/config.rs:479:9: error[E0308]: mismatched types tests/testsuite/config.rs:491:9: error[E0308]: mismatched types tests/testsuite/config.rs:496:9: error[E0308]: mismatched types tests/testsuite/config.rs:501:9: error[E0308]: mismatched types tests/testsuite/config.rs:506:9: error[E0308]: mismatched types tests/testsuite/config.rs:512:9: error[E0308]: mismatched types tests/testsuite/config.rs:582:9: error[E0308]: mismatched types tests/testsuite/config.rs:660:9: error[E0308]: mismatched types tests/testsuite/config.rs:666:9: error[E0308]: mismatched types tests/testsuite/config.rs:672:9: error[E0308]: mismatched types tests/testsuite/config.rs:678:9: error[E0308]: mismatched types error: aborting due to 21 previous errors error: Could not compile `cargo`. warning: build failed, waiting for other jobs to finish... error: build failed Rehash of @QuietMisdreavus' #4720 now that `--short-message` is stable (thanks for the ping @pickfire!). Feedback welcome.
2 parents 578e253 + 2c704d8 commit 972ccba

File tree

7 files changed

+51
-10
lines changed

7 files changed

+51
-10
lines changed

src/bin/cargo/command_prelude.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub trait AppExt: Sized {
127127
opt("message-format", "Error format")
128128
.value_name("FMT")
129129
.case_insensitive(true)
130-
.possible_values(&["human", "json"])
130+
.possible_values(&["human", "json", "short"])
131131
.default_value("human"),
132132
)
133133
}
@@ -270,6 +270,8 @@ pub trait ArgMatchesExt {
270270
MessageFormat::Json
271271
} else if f.eq_ignore_ascii_case("human") {
272272
MessageFormat::Human
273+
} else if f.eq_ignore_ascii_case("short") {
274+
MessageFormat::Short
273275
} else {
274276
panic!("Impossible message format: {:?}", f)
275277
}

src/cargo/core/compiler/build_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl BuildConfig {
100100
pub enum MessageFormat {
101101
Human,
102102
Json,
103+
Short,
103104
}
104105

105106
/// The general "mode" of what to do.

src/cargo/core/compiler/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
605605
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
606606
}
607607

608-
if bcx.build_config.json_messages() {
609-
rustdoc.arg("--error-format").arg("json");
610-
}
608+
add_error_format(bcx, &mut rustdoc);
611609

612610
if let Some(ref args) = bcx.extra_args_for(unit) {
613611
rustdoc.args(args);
@@ -706,6 +704,14 @@ fn add_color(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
706704
}
707705
}
708706

707+
fn add_error_format(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
708+
match bcx.build_config.message_format {
709+
MessageFormat::Human => (),
710+
MessageFormat::Json => { cmd.arg("--error-format").arg("json"); },
711+
MessageFormat::Short => { cmd.arg("--error-format").arg("short"); },
712+
}
713+
}
714+
709715
fn build_base_args<'a, 'cfg>(
710716
cx: &mut Context<'a, 'cfg>,
711717
cmd: &mut ProcessBuilder,
@@ -732,10 +738,7 @@ fn build_base_args<'a, 'cfg>(
732738

733739
add_path_args(bcx, unit, cmd);
734740
add_color(bcx, cmd);
735-
736-
if bcx.build_config.json_messages() {
737-
cmd.arg("--error-format").arg("json");
738-
}
741+
add_error_format(bcx, cmd);
739742

740743
if !test {
741744
for crate_type in crate_types.iter() {

src/etc/_cargo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ case $state in
364364
'(--lib --doc --bin --test --bench)--example=[example name]' \
365365
'(--lib --doc --bin --example --bench)--test=[test name]' \
366366
'(--lib --doc --bin --example --test)--bench=[benchmark name]' \
367-
'--message-format:error format:(human json)' \
367+
'--message-format:error format:(human json short)' \
368368
'--frozen[require lock and cache up to date]' \
369369
'--locked[require lock up to date]'
370370
;;

tests/testsuite/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,7 @@ fn wrong_message_format_option() {
35713571
execs().with_status(1).with_stderr_contains(
35723572
"\
35733573
error: 'XML' isn't a valid value for '--message-format <FMT>'
3574-
<tab>[possible values: human, json]
3574+
<tab>[possible values: human, json, short]
35753575
",
35763576
),
35773577
);

tests/testsuite/check.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,23 @@ fn check_artifacts() {
722722
);
723723
}
724724

725+
#[test]
726+
fn short_message_format() {
727+
let foo = project()
728+
.file("src/lib.rs", "fn foo() { let _x: bool = 'a'; }")
729+
.build();
730+
assert_that(
731+
foo.cargo("check --message-format=short"),
732+
execs().with_status(101).with_stderr_contains(
733+
"\
734+
src/lib.rs:1:27: error[E0308]: mismatched types
735+
error: aborting due to previous error
736+
error: Could not compile `foo`.
737+
",
738+
),
739+
);
740+
}
741+
725742
#[test]
726743
fn proc_macro() {
727744
let p = project()

tests/testsuite/doc.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,3 +1450,21 @@ fn doc_message_format() {
14501450
),
14511451
);
14521452
}
1453+
1454+
#[test]
1455+
fn short_message_format() {
1456+
if !is_nightly() {
1457+
// This can be removed once 1.30 is stable (rustdoc --error-format stabilized).
1458+
return;
1459+
}
1460+
let p = project().file("src/lib.rs", BAD_INTRA_LINK_LIB).build();
1461+
assert_that(
1462+
p.cargo("doc --message-format=short"),
1463+
execs().with_status(101).with_stderr_contains(
1464+
"\
1465+
src/lib.rs:4:6: error: `[bad_link]` cannot be resolved, ignoring it...
1466+
error: Could not document `foo`.
1467+
",
1468+
),
1469+
);
1470+
}

0 commit comments

Comments
 (0)