Skip to content

Commit 6f18507

Browse files
committed
Display update message in report
1 parent 704540d commit 6f18507

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

src/cargo/core/compiler/future_incompat.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ pub struct OnDiskReports {
7575
struct OnDiskReport {
7676
/// Unique reference to the report for the `--id` CLI flag.
7777
id: u32,
78+
/// A (possibly empty) message describing which affected
79+
/// packages have newer versions available
80+
update_message: String,
7881
/// Report, suitable for printing to the console.
7982
/// Maps package names to the corresponding report
8083
/// We use a `BTreeMap` so that the iteration order
@@ -96,6 +99,7 @@ impl OnDiskReports {
9699
/// Saves a new report.
97100
pub fn save_report(
98101
ws: &Workspace<'_>,
102+
update_message: String,
99103
per_package_reports: &[FutureIncompatReportPackage],
100104
) -> OnDiskReports {
101105
let mut current_reports = match Self::load(ws) {
@@ -110,6 +114,7 @@ impl OnDiskReports {
110114
};
111115
let report = OnDiskReport {
112116
id: current_reports.next_id,
117+
update_message,
113118
per_package: render_report(per_package_reports),
114119
};
115120
current_reports.next_id += 1;
@@ -192,7 +197,10 @@ impl OnDiskReports {
192197
available
193198
)
194199
})?;
195-
let to_display = if let Some(package) = package {
200+
201+
let mut to_display = report.update_message.clone();
202+
203+
let package_report = if let Some(package) = package {
196204
report
197205
.per_package
198206
.get(package)
@@ -205,7 +213,7 @@ impl OnDiskReports {
205213
iter_join(report.per_package.keys(), ", ")
206214
)
207215
})?
208-
.clone()
216+
.to_string()
209217
} else {
210218
report
211219
.per_package
@@ -214,6 +222,8 @@ impl OnDiskReports {
214222
.collect::<Vec<_>>()
215223
.join("\n")
216224
};
225+
to_display += &package_report;
226+
217227
let to_display = if config.shell().err_supports_color() {
218228
to_display
219229
} else {

src/cargo/core/compiler/job_queue.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,26 @@ impl<'cfg> DrainState<'cfg> {
928928
)));
929929
}
930930

931-
let on_disk_reports =
932-
OnDiskReports::save_report(bcx.ws, &self.per_package_future_incompat_reports);
931+
let updated_versions = get_updates(bcx.ws, &package_ids).unwrap_or(String::new());
932+
933+
let update_message = if !updated_versions.is_empty() {
934+
format!(
935+
"
936+
- Some affected dependencies have newer versions available.
937+
You may want to consider updating them to a newer version to see if the issue has been fixed.
938+
939+
{updated_versions}\n",
940+
updated_versions = updated_versions
941+
)
942+
} else {
943+
String::new()
944+
};
945+
946+
let on_disk_reports = OnDiskReports::save_report(
947+
bcx.ws,
948+
update_message.clone(),
949+
&self.per_package_future_incompat_reports,
950+
);
933951
let report_id = on_disk_reports.last_id();
934952

935953
if bcx.build_config.future_incompat_report {
@@ -953,20 +971,6 @@ impl<'cfg> DrainState<'cfg> {
953971
})
954972
.collect::<Vec<_>>()
955973
.join("\n");
956-
957-
let updated_versions = get_updates(bcx.ws, &package_ids).unwrap_or(String::new());
958-
959-
let update_message = if !updated_versions.is_empty() {
960-
format!(
961-
"
962-
- Some affected dependencies have updates available:
963-
{updated_versions}",
964-
updated_versions = updated_versions
965-
)
966-
} else {
967-
String::new()
968-
};
969-
970974
drop(bcx.config.shell().note(&format!(
971975
"
972976
To solve this problem, you can try the following approaches:

tests/testsuite/future_incompat_report.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,22 @@ fn suggestions_for_updates() {
419419
// in a long while?).
420420
p.cargo("update -p without_updates").run();
421421

422+
let update_message = "\
423+
- Some affected dependencies have newer versions available.
424+
You may want to consider updating them to a newer version to see if the issue has been fixed.
425+
426+
big_update v1.0.0 has the following newer versions available: 2.0.0
427+
with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1
428+
";
429+
422430
p.cargo("check -Zfuture-incompat-report -Zunstable-options --future-incompat-report")
423431
.masquerade_as_nightly_cargo()
424432
.env("RUSTFLAGS", "-Zfuture-incompat-test")
425-
.with_stderr_contains(
426-
"\
427-
- Some affected dependencies have updates available:
428-
big_update v1.0.0 has the following newer versions available: 2.0.0
429-
with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1
430-
",
431-
)
433+
.with_stderr_contains(update_message)
432434
.run();
435+
436+
p.cargo("report future-incompatibilities")
437+
.masquerade_as_nightly_cargo()
438+
.with_stdout_contains(update_message)
439+
.run()
433440
}

0 commit comments

Comments
 (0)