Skip to content

Commit db457d9

Browse files
Fixing issue #10834:
- Adding display of which target failed to compile - Consistent messages for warnings/errors. - Fixing assertions on related tests.
1 parent 12dbca3 commit db457d9

File tree

8 files changed

+31
-18
lines changed

8 files changed

+31
-18
lines changed

src/cargo/core/compiler/job_queue/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub use self::job_state::JobState;
134134
use super::context::OutputFile;
135135
use super::timings::Timings;
136136
use super::{BuildContext, BuildPlan, CompileMode, Context, Unit};
137+
use crate::core::compiler::descriptive_pkg_name;
137138
use crate::core::compiler::future_incompat::{
138139
self, FutureBreakageItem, FutureIncompatReportPackage,
139140
};
@@ -1000,15 +1001,8 @@ impl<'cfg> DrainState<'cfg> {
10001001
None | Some(_) => return,
10011002
};
10021003
let unit = &self.active[&id];
1003-
let mut message = format!("`{}` ({}", unit.pkg.name(), unit.target.description_named());
1004-
if unit.mode.is_rustc_test() && !(unit.target.is_test() || unit.target.is_bench()) {
1005-
message.push_str(" test");
1006-
} else if unit.mode.is_doc_test() {
1007-
message.push_str(" doctest");
1008-
} else if unit.mode.is_doc() {
1009-
message.push_str(" doc");
1010-
}
1011-
message.push_str(") generated ");
1004+
let mut message = descriptive_pkg_name(&unit.pkg.name(), &unit.target, &unit.mode);
1005+
message.push_str(" generated ");
10121006
match count.total {
10131007
1 => message.push_str("1 warning"),
10141008
n => drop(write!(message, "{} warnings", n)),

src/cargo/core/compiler/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
467467
1 => " due to previous error".to_string(),
468468
count => format!(" due to {} previous errors", count),
469469
};
470-
format!("could not compile `{}`{}{}", name, errors, warnings)
470+
let name = descriptive_pkg_name(&name, &target, &mode);
471+
format!("could not compile {name}{errors}{warnings}")
471472
});
472473

473474
if let Err(e) = result {
@@ -1776,3 +1777,19 @@ fn replay_output_cache(
17761777
Ok(())
17771778
})
17781779
}
1780+
1781+
/// Provides a package name with descriptive target information,
1782+
/// e.g., '`foo` (bin "bar" test)', '`foo` (lib doctest)'.
1783+
fn descriptive_pkg_name(name: &str, target: &Target, mode: &CompileMode) -> String {
1784+
let desc_name = target.description_named();
1785+
let mode = if mode.is_rustc_test() && !(target.is_test() || target.is_bench()) {
1786+
" test"
1787+
} else if mode.is_doc_test() {
1788+
" doctest"
1789+
} else if mode.is_doc() {
1790+
" doc"
1791+
} else {
1792+
""
1793+
};
1794+
format!("`{name}` ({desc_name}{mode})")
1795+
}

tests/testsuite/build.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,9 @@ fn cargo_compile_with_invalid_code() {
639639

640640
p.cargo("build")
641641
.with_status(101)
642-
.with_stderr_contains("[ERROR] could not compile `foo` due to previous error\n")
642+
.with_stderr_contains(
643+
"[ERROR] could not compile `foo` (bin \"foo\") due to previous error\n",
644+
)
643645
.run();
644646
assert!(p.root().join("Cargo.lock").is_file());
645647
}
@@ -5699,7 +5701,7 @@ fn signal_display() {
56995701
"\
57005702
[COMPILING] pm [..]
57015703
[COMPILING] foo [..]
5702-
[ERROR] could not compile `foo`
5704+
[ERROR] could not compile `foo` [..]
57035705
57045706
Caused by:
57055707
process didn't exit successfully: `rustc [..]` (signal: 6, SIGABRT: process abort signal)

tests/testsuite/build_script.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ fn build_deps_not_for_normal() {
16781678
.with_stderr_contains("[..]can't find crate for `aaaaa`[..]")
16791679
.with_stderr_contains(
16801680
"\
1681-
[ERROR] could not compile `foo` due to previous error
1681+
[ERROR] could not compile `foo` (lib) due to previous error
16821682
16831683
Caused by:
16841684
process didn't exit successfully: [..]

tests/testsuite/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ fn short_message_format() {
804804
.with_stderr_contains(
805805
"\
806806
src/lib.rs:1:27: error[E0308]: mismatched types
807-
error: could not compile `foo` due to previous error
807+
error: could not compile `foo` (lib) due to previous error
808808
",
809809
)
810810
.run();
@@ -1251,7 +1251,7 @@ fn check_fixable_error_no_fix() {
12511251
[CHECKING] foo v0.0.1 ([..])
12521252
{}\
12531253
[WARNING] `foo` (lib) generated 1 warning
1254-
[ERROR] could not compile `foo` due to previous error; 1 warning emitted
1254+
[ERROR] could not compile `foo` (lib) due to previous error; 1 warning emitted
12551255
",
12561256
rustc_message
12571257
);

tests/testsuite/fix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn do_not_fix_broken_builds() {
2929
p.cargo("fix --allow-no-vcs")
3030
.env("__CARGO_FIX_YOLO", "1")
3131
.with_status(101)
32-
.with_stderr_contains("[ERROR] could not compile `foo` due to previous error")
32+
.with_stderr_contains("[ERROR] could not compile `foo` (lib) due to previous error")
3333
.run();
3434
assert!(p.read_file("src/lib.rs").contains("let mut x = 3;"));
3535
}

tests/testsuite/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ fn compile_failure() {
881881
.with_status(101)
882882
.with_stderr_contains(
883883
"\
884-
[ERROR] could not compile `foo` due to previous error
884+
[ERROR] could not compile `foo` (bin \"foo\") due to previous error
885885
[ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be \
886886
found at `[..]target`
887887
",

tests/testsuite/messages.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn deduplicate_errors() {
136136
.with_stderr(&format!(
137137
"\
138138
[COMPILING] foo v0.0.1 [..]
139-
{}error: could not compile `foo` due to previous error
139+
{}error: could not compile `foo` (lib) due to previous error
140140
",
141141
rustc_message
142142
))

0 commit comments

Comments
 (0)