diff --git a/src/cargo/core/compiler/future_incompat.rs b/src/cargo/core/compiler/future_incompat.rs index f184b472c..9d2324748 100644 --- a/src/cargo/core/compiler/future_incompat.rs +++ b/src/cargo/core/compiler/future_incompat.rs @@ -140,16 +140,10 @@ impl OnDiskReports { mut self, ws: &Workspace<'_>, suggestion_message: String, - per_package_reports: &[FutureIncompatReportPackage], + per_package: BTreeMap, ) -> 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; + if let Some(existing_id) = self.has_report(&per_package) { + return existing_id; } let report = OnDiskReport { @@ -189,6 +183,14 @@ impl OnDiskReports { saved_id } + /// Returns the ID of a report if it is already on disk. + fn has_report(&self, rendered_per_package: &BTreeMap) -> Option { + self.reports + .iter() + .find(|existing| &existing.per_package == rendered_per_package) + .map(|report| report.id) + } + /// Loads the on-disk reports. pub fn load(ws: &Workspace<'_>) -> CargoResult { let report_file = match ws.build_dir().open_ro_shared( @@ -408,7 +410,14 @@ pub fn save_and_display_report( OnDiskReports::default() } }; - let report_id = current_reports.next_id; + + let rendered_report = render_report(per_package_future_incompat_reports); + + // If the report is already on disk, then it will reuse the same ID, + // otherwise prepare for the next ID. + let report_id = current_reports + .has_report(&rendered_report) + .unwrap_or(current_reports.next_id); // Get a list of unique and sorted package name/versions. let package_ids: BTreeSet<_> = per_package_future_incompat_reports @@ -481,11 +490,8 @@ https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch update_message = update_message, ); - let saved_report_id = current_reports.save_report( - bcx.ws, - suggestion_message.clone(), - per_package_future_incompat_reports, - ); + let saved_report_id = + current_reports.save_report(bcx.ws, suggestion_message.clone(), rendered_report); if bcx.build_config.future_incompat_report { drop(bcx.gctx.shell().note(&suggestion_message)); diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index 7ee09e097..0753f33ba 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -102,7 +102,7 @@ fix to the maintainers (e.g. by creating a pull request): - foo@0.0.0 - Repository: - - Detailed warning command: `cargo report future-incompatibilities --id 2 --package foo@0.0.0` + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package foo@0.0.0` - If waiting for an upstream fix is not an option, you can use the `[patch]` section in `Cargo.toml` to use your own version of the dependency. For more @@ -192,7 +192,7 @@ fix to the maintainers (e.g. by creating a pull request): - bar@1.0.0 - Repository: https://example.com/ - - Detailed warning command: `cargo report future-incompatibilities --id 2 --package bar@1.0.0` + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` - If waiting for an upstream fix is not an option, you can use the `[patch]` section in `Cargo.toml` to use your own version of the dependency. For more @@ -708,7 +708,7 @@ fix to the maintainers (e.g. by creating a pull request): - bar@1.0.0 - Repository: https://example.com/ - - Detailed warning command: `cargo report future-incompatibilities --id 2 --package bar@1.0.0` + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` - If waiting for an upstream fix is not an option, you can use the `[patch]` section in `Cargo.toml` to use your own version of the dependency. For more