Skip to content

Commit 87ce527

Browse files
committed
Avoid saving the same future_incompat warning multiple times
Fixes #11594.
1 parent f6cf5ab commit 87ce527

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/cargo/core/compiler/future_incompat.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,30 @@ impl Default for OnDiskReports {
100100
}
101101

102102
impl OnDiskReports {
103-
/// Saves a new report.
103+
/// Saves a new report returning its id
104104
pub fn save_report(
105105
mut self,
106106
ws: &Workspace<'_>,
107107
suggestion_message: String,
108108
per_package_reports: &[FutureIncompatReportPackage],
109-
) {
109+
) -> u32 {
110+
let per_package = render_report(per_package_reports);
111+
112+
if let Some(existing_report) = self
113+
.reports
114+
.iter()
115+
.find(|existing| existing.per_package == per_package)
116+
{
117+
return existing_report.id;
118+
}
119+
110120
let report = OnDiskReport {
111121
id: self.next_id,
112122
suggestion_message,
113-
per_package: render_report(per_package_reports),
123+
per_package,
114124
};
125+
126+
let saved_id = report.id;
115127
self.next_id += 1;
116128
self.reports.push(report);
117129
if self.reports.len() > MAX_REPORTS {
@@ -138,6 +150,8 @@ impl OnDiskReports {
138150
&mut ws.config().shell(),
139151
);
140152
}
153+
154+
saved_id
141155
}
142156

143157
/// Loads the on-disk reports.
@@ -450,7 +464,7 @@ https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch
450464
update_message = update_message,
451465
);
452466

453-
current_reports.save_report(
467+
let saved_report_id = current_reports.save_report(
454468
bcx.ws,
455469
suggestion_message.clone(),
456470
per_package_future_incompat_reports,
@@ -461,14 +475,14 @@ https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch
461475
drop(bcx.config.shell().note(&format!(
462476
"this report can be shown with `cargo report \
463477
future-incompatibilities --id {}`",
464-
report_id
478+
saved_report_id
465479
)));
466480
} else if should_display_message {
467481
drop(bcx.config.shell().note(&format!(
468482
"to see what the problems were, use the option \
469483
`--future-incompat-report`, or run `cargo report \
470484
future-incompatibilities --id {}`",
471-
report_id
485+
saved_report_id
472486
)));
473487
}
474488
}

0 commit comments

Comments
 (0)