Skip to content

Commit

Permalink
Auto merge of #11648 - peterallin:peterallin/11594, r=epage
Browse files Browse the repository at this point in the history
Avoid saving the same future_incompat warning multiple times

### What does this PR try to resolve?

Each time a build, that causes future_incompat warnings, is run, a report about each
warning is created and saved to disk with a new id quicky filling up the JSON file. This PR
adds a check if the report is already on disk and avoids saving a new instance of it.

Fixes #11594.

### How should we test and review this PR?

Perform a build that gives one or more future_incompat warnings, and see that they
are added to the  JSON file only once when the build is repeated.
  • Loading branch information
bors committed Jan 30, 2023
2 parents 5244300 + 87ce527 commit 0de0e80
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/cargo/core/compiler/future_incompat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,30 @@ impl Default for OnDiskReports {
}

impl OnDiskReports {
/// Saves a new report.
/// Saves a new report returning its id
pub fn save_report(
mut self,
ws: &Workspace<'_>,
suggestion_message: String,
per_package_reports: &[FutureIncompatReportPackage],
) {
) -> u32 {
let per_package = render_report(per_package_reports);

if let Some(existing_report) = self
.reports
.iter()
.find(|existing| existing.per_package == per_package)
{
return existing_report.id;
}

let report = OnDiskReport {
id: self.next_id,
suggestion_message,
per_package: render_report(per_package_reports),
per_package,
};

let saved_id = report.id;
self.next_id += 1;
self.reports.push(report);
if self.reports.len() > MAX_REPORTS {
Expand All @@ -138,6 +150,8 @@ impl OnDiskReports {
&mut ws.config().shell(),
);
}

saved_id
}

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

current_reports.save_report(
let saved_report_id = current_reports.save_report(
bcx.ws,
suggestion_message.clone(),
per_package_future_incompat_reports,
Expand All @@ -461,14 +475,14 @@ https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch
drop(bcx.config.shell().note(&format!(
"this report can be shown with `cargo report \
future-incompatibilities --id {}`",
report_id
saved_report_id
)));
} else if should_display_message {
drop(bcx.config.shell().note(&format!(
"to see what the problems were, use the option \
`--future-incompat-report`, or run `cargo report \
future-incompatibilities --id {}`",
report_id
saved_report_id
)));
}
}

0 comments on commit 0de0e80

Please sign in to comment.