From 941c414a901140969707c8e7b5c6656992db684f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 06:59:29 -0700 Subject: [PATCH 1/7] Add test for cached report id --- tests/testsuite/future_incompat_report.rs | 121 ++++++++++++++++++++-- 1 file changed, 113 insertions(+), 8 deletions(-) diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index bb4e6dbecec..ac8a86471c8 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -15,14 +15,47 @@ use super::config::write_config_toml; // An arbitrary lint (unused_variables) that triggers a lint. // We use a special flag to force it to generate a report. -const FUTURE_EXAMPLE: &'static str = "fn main() { let x = 1; }"; +const FUTURE_EXAMPLE: &'static str = "pub fn foo() { let x = 1; }"; // Some text that will be displayed when the lint fires. const FUTURE_OUTPUT: &'static str = "[..]unused variable[..]"; -fn simple_project() -> Project { +/// A project with a future-incompat error in the local package. +fn local_project() -> Project { project() .file("Cargo.toml", &basic_manifest("foo", "0.0.0")) - .file("src/main.rs", FUTURE_EXAMPLE) + .file("src/lib.rs", FUTURE_EXAMPLE) + .build() +} + +/// A project with a future-incompat error in a dependency. +fn dependency_project() -> Project { + Package::new("bar", "1.0.0") + .file( + "Cargo.toml", + r#" + [package] + name = "bar" + version = "1.0.0" + edition = "2015" + repository = "https://example.com/" + "#, + ) + .file("src/lib.rs", FUTURE_EXAMPLE) + .publish(); + project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "1.0.0" + edition = "2015" + + [dependencies] + bar = "1.0" + "#, + ) + .file("src/lib.rs", "") .build() } @@ -31,7 +64,7 @@ fn simple_project() -> Project { reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn output_on_stable() { - let p = simple_project(); + let p = local_project(); p.cargo("check") .env("RUSTFLAGS", "-Zfuture-incompat-test") @@ -48,7 +81,7 @@ fn output_on_stable() { // This feature is stable, and should not be gated #[cargo_test] fn no_gate_future_incompat_report() { - let p = simple_project(); + let p = local_project(); p.cargo("check --future-incompat-report") .with_status(0) @@ -98,7 +131,7 @@ fn test_zero_future_incompat() { reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn test_single_crate() { - let p = simple_project(); + let p = local_project(); for command in &["build", "check", "rustc", "test"] { let check_has_future_compat = || { @@ -315,7 +348,7 @@ The package `second-dep v0.0.2` currently triggers the following future incompat reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn color() { - let p = simple_project(); + let p = local_project(); p.cargo("check") .env("RUSTFLAGS", "-Zfuture-incompat-test") @@ -337,7 +370,7 @@ fn color() { reason = "-Zfuture-incompat-test requires nightly (permanently)" )] fn bad_ids() { - let p = simple_project(); + let p = local_project(); p.cargo("report future-incompatibilities --id 1") .with_status(101) @@ -451,3 +484,75 @@ with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3. "#]]) .run(); } + +#[cargo_test( + nightly, + reason = "-Zfuture-incompat-test requires nightly (permanently)" +)] +fn correct_report_id_when_cached() { + // Checks for a bug where the `--id` value was off-by-one when the report + // is already cached. + let p = dependency_project(); + + p.cargo("check --future-incompat-report") + .env("RUSTFLAGS", "-Zfuture-incompat-test") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 1 package to latest compatible version +[DOWNLOADING] crates ... +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) +[CHECKING] bar v1.0.0 +[CHECKING] foo v1.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 +[NOTE] +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +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 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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` + +"#]]) + .run(); + + p.cargo("check --future-incompat-report") + .env("RUSTFLAGS", "-Zfuture-incompat-test") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 +[NOTE] +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +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` + +- 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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` + +"#]]) + .run(); +} From afdfd9263eec154bcf883fac72beb8ecf79441d2 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 15:52:43 -0700 Subject: [PATCH 2/7] Add some more explicit future-incompat tests This updates some tests to include the full output for both a local crate and a dependency. --- tests/testsuite/future_incompat_report.rs | 166 +++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index ac8a86471c8..7ee09e0971b 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -63,17 +63,181 @@ fn dependency_project() -> Project { nightly, reason = "-Zfuture-incompat-test requires nightly (permanently)" )] -fn output_on_stable() { +fn incompat_in_local_crate() { + // A simple example where a local crate triggers a future-incompatibility warning. let p = local_project(); p.cargo("check") .env("RUSTFLAGS", "-Zfuture-incompat-test") .with_stderr_data(str![[r#" +[CHECKING] foo v0.0.0 ([ROOT]/foo) +[WARNING] unused variable: `x` ... + +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 ([ROOT]/foo) +[NOTE] to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1` + +"#]]) + .run(); + + p.cargo("check --future-incompat-report") + .env("RUSTFLAGS", "-Zfuture-incompat-test") + .with_stderr_data(str![[r#" [WARNING] unused variable: `x` ... + +[WARNING] `foo` (lib) generated 1 warning +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 ([ROOT]/foo) +[NOTE] +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +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` + +- 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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` + +"#]]) + .run(); + + p.cargo("report future-incompatibilities --id 1") + .with_stdout_data(str![[r#" +The following warnings were discovered during the build. These warnings are an +indication that the packages contain code that will become an error in a +future release of Rust. These warnings typically cover changes to close +soundness problems, unintended or undocumented behavior, or critical problems +that cannot be fixed in a backwards-compatible fashion, and are not expected +to be in wide use. + +Each warning should contain a link for more information on what the warning +means and how to resolve it. + + +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +fix to the maintainers (e.g. by creating a pull request): + + - foo@0.0.0 + - Repository: + - 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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +The package `foo v0.0.0 ([ROOT]/foo)` currently triggers the following future incompatibility lints: +> [WARNING] unused variable: `x` +... + +"#]]) + .run(); +} + +#[cargo_test( + nightly, + reason = "-Zfuture-incompat-test requires nightly (permanently)" +)] +fn incompat_in_dependency() { + // A simple example where a remote dependency triggers a future-incompatibility warning. + let p = dependency_project(); + + p.cargo("check") + .env("RUSTFLAGS", "-Zfuture-incompat-test") + .with_stderr_data(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 1 package to latest compatible version +[DOWNLOADING] crates ... +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) +[CHECKING] bar v1.0.0 +[CHECKING] foo v1.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 [NOTE] to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1` +"#]]) + .run(); + + p.cargo("check --future-incompat-report") + .env("RUSTFLAGS", "-Zfuture-incompat-test") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 +[NOTE] +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +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` + +- 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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` + +"#]]) + .run(); + + p.cargo("report future-incompatibilities --id 1") + .with_stdout_data(str![[r#" +The following warnings were discovered during the build. These warnings are an +indication that the packages contain code that will become an error in a +future release of Rust. These warnings typically cover changes to close +soundness problems, unintended or undocumented behavior, or critical problems +that cannot be fixed in a backwards-compatible fashion, and are not expected +to be in wide use. + +Each warning should contain a link for more information on what the warning +means and how to resolve it. + + +To solve this problem, you can try the following approaches: + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +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 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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +The package `bar v1.0.0` currently triggers the following future incompatibility lints: +> [WARNING] unused variable: `x` +... + "#]]) .run(); } From 3fb97ecf2881eb06dad10b58e029995d9a8b1e37 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 15:10:02 -0700 Subject: [PATCH 3/7] Fix off-by-one error when future-incompat report is cached This fixes a problem introduced by https://github.com/rust-lang/cargo/pull/11648 where the future-incompat report will tell you to run with an `--id` flag with the wrong value if the report is already cached. The solution is to add a method to determine which ID to use for the suggestions *before* attempting to save the report. --- src/cargo/core/compiler/future_incompat.rs | 36 +++++++++++++--------- tests/testsuite/future_incompat_report.rs | 6 ++-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/cargo/core/compiler/future_incompat.rs b/src/cargo/core/compiler/future_incompat.rs index f184b472c3a..9d232474807 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 7ee09e0971b..0753f33ba9f 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 From 497cfe5e48979d6febf0e84dd5e75f9bc1eb75e3 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 16:10:42 -0700 Subject: [PATCH 4/7] Remove excess trailing space --- src/cargo/core/compiler/future_incompat.rs | 2 +- tests/testsuite/future_incompat_report.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/future_incompat.rs b/src/cargo/core/compiler/future_incompat.rs index 9d232474807..efa9fc80a55 100644 --- a/src/cargo/core/compiler/future_incompat.rs +++ b/src/cargo/core/compiler/future_incompat.rs @@ -485,7 +485,7 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - ", +", upstream_info = upstream_info, update_message = update_message, ); diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index 0753f33ba9f..f94c1ffb901 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -108,7 +108,7 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - + [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]]) @@ -143,7 +143,7 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - + The package `foo v0.0.0 ([ROOT]/foo)` currently triggers the following future incompatibility lints: > [WARNING] unused variable: `x` ... @@ -198,7 +198,7 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - + [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]]) @@ -233,7 +233,7 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - + The package `bar v1.0.0` currently triggers the following future incompatibility lints: > [WARNING] unused variable: `x` ... @@ -686,7 +686,7 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - + [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]]) @@ -714,7 +714,7 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - + [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]]) From 4d961ed19c26b3a9476d8e5da378ed2e97a849cf Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 16:13:21 -0700 Subject: [PATCH 5/7] Don't show a suggestion to update dependencies This removes the suggestion to update dependencies when the future incompat error comes from the local crate. It doesn't make sense to suggest that. --- src/cargo/core/compiler/future_incompat.rs | 24 ++++++++++---- src/cargo/core/compiler/job_queue/mod.rs | 10 ++++-- tests/testsuite/future_incompat_report.rs | 37 +--------------------- 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/src/cargo/core/compiler/future_incompat.rs b/src/cargo/core/compiler/future_incompat.rs index efa9fc80a55..fe9967e3ac6 100644 --- a/src/cargo/core/compiler/future_incompat.rs +++ b/src/cargo/core/compiler/future_incompat.rs @@ -70,6 +70,8 @@ pub struct FutureIncompatReport { /// Structure used for collecting reports in-memory. pub struct FutureIncompatReportPackage { pub package_id: PackageId, + /// Whether or not this is a local package, or a remote dependency. + pub is_local: bool, pub items: Vec, } @@ -470,8 +472,15 @@ You may want to consider updating them to a newer version to see if the issue ha .collect::>() .join("\n"); - let suggestion_message = format!( - " + let all_is_local = per_package_future_incompat_reports + .iter() + .all(|report| report.is_local); + + let suggestion_message = if all_is_local { + String::new() + } else { + format!( + " To solve this problem, you can try the following approaches: {update_message} @@ -486,15 +495,18 @@ section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section ", - upstream_info = upstream_info, - update_message = update_message, - ); + upstream_info = upstream_info, + update_message = update_message, + ) + }; 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)); + if !suggestion_message.is_empty() { + drop(bcx.gctx.shell().note(&suggestion_message)); + } drop(bcx.gctx.shell().note(&format!( "this report can be shown with `cargo report \ future-incompatibilities --id {}`", diff --git a/src/cargo/core/compiler/job_queue/mod.rs b/src/cargo/core/compiler/job_queue/mod.rs index b04e6a42bae..1b63cdabca6 100644 --- a/src/cargo/core/compiler/job_queue/mod.rs +++ b/src/cargo/core/compiler/job_queue/mod.rs @@ -700,9 +700,15 @@ impl<'gctx> DrainState<'gctx> { } } Message::FutureIncompatReport(id, items) => { - let package_id = self.active[&id].pkg.package_id(); + let unit = &self.active[&id]; + let package_id = unit.pkg.package_id(); + let is_local = unit.is_local(); self.per_package_future_incompat_reports - .push(FutureIncompatReportPackage { package_id, items }); + .push(FutureIncompatReportPackage { + package_id, + is_local, + items, + }); } Message::Token(acquired_token) => { let token = acquired_token.context("failed to acquire jobserver token")?; diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index f94c1ffb901..7e71bb71e4e 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -91,24 +91,6 @@ fn incompat_in_local_crate() { [WARNING] `foo` (lib) generated 1 warning [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [WARNING] the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 ([ROOT]/foo) -[NOTE] -To solve this problem, you can try the following approaches: - - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): - - - foo@0.0.0 - - Repository: - - 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 -information, see: -https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]]) @@ -127,23 +109,6 @@ Each warning should contain a link for more information on what the warning means and how to resolve it. -To solve this problem, you can try the following approaches: - - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): - - - foo@0.0.0 - - Repository: - - 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 -information, see: -https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - The package `foo v0.0.0 ([ROOT]/foo)` currently triggers the following future incompatibility lints: > [WARNING] unused variable: `x` ... @@ -352,7 +317,7 @@ frequency = 'never' ... [WARNING] the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 ([ROOT]/foo) ... - - foo@0.0.0 +[NOTE] this report can be shown with `cargo report future-incompatibilities --id [..]` ... ") .run(); From b17b9a4b906e47c81c290b896bff8c5bf978ac54 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 16:24:51 -0700 Subject: [PATCH 6/7] Elaborate the full output when there are newer versions available This output was never tested. --- tests/testsuite/future_incompat_report.rs | 95 ++++++++++++++++++++++- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index 7e71bb71e4e..b1e5f060c3d 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -553,6 +553,7 @@ fn suggestions_for_updates() { [package] name = "foo" version = "0.1.0" + edition = "2015" [dependencies] with_updates = "1" @@ -591,25 +592,111 @@ fn suggestions_for_updates() { .masquerade_as_nightly_cargo(&["future-incompat-test"]) .env("RUSTFLAGS", "-Zfuture-incompat-test") .with_stderr_data(str![[r#" -... +[DOWNLOADING] crates ... +[DOWNLOADED] without_updates v1.0.0 (registry `dummy-registry`) +[DOWNLOADED] with_updates v1.0.0 (registry `dummy-registry`) +[DOWNLOADED] big_update v1.0.0 (registry `dummy-registry`) +[CHECKING] with_updates v1.0.0 +[CHECKING] big_update v1.0.0 +[CHECKING] without_updates v1.0.0 +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] the following packages contain code that will be rejected by a future version of Rust: big_update v1.0.0, with_updates v1.0.0, without_updates v1.0.0 +[NOTE] +To solve this problem, you can try the following approaches: + + - Some affected dependencies have newer versions available. You may want to consider updating them to a newer version to see if the issue has been fixed. big_update v1.0.0 has the following newer versions available: 2.0.0 with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 -... -"#]]) + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +fix to the maintainers (e.g. by creating a pull request): + + - big_update@1.0.0 + - Repository: + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package big_update@1.0.0` + + - with_updates@1.0.0 + - Repository: + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package with_updates@1.0.0` + + - without_updates@1.0.0 + - Repository: + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package without_updates@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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` + +"#]].unordered()) .run(); p.cargo("report future-incompatibilities") .with_stdout_data(str![[r#" -... +The following warnings were discovered during the build. These warnings are an +indication that the packages contain code that will become an error in a +future release of Rust. These warnings typically cover changes to close +soundness problems, unintended or undocumented behavior, or critical problems +that cannot be fixed in a backwards-compatible fashion, and are not expected +to be in wide use. + +Each warning should contain a link for more information on what the warning +means and how to resolve it. + + +To solve this problem, you can try the following approaches: + + - Some affected dependencies have newer versions available. You may want to consider updating them to a newer version to see if the issue has been fixed. big_update v1.0.0 has the following newer versions available: 2.0.0 with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 + + +- If the issue is not solved by updating the dependencies, a fix has to be +implemented by those dependencies. You can help with that by notifying the +maintainers of this problem (e.g. by creating a bug report) or by proposing a +fix to the maintainers (e.g. by creating a pull request): + + - big_update@1.0.0 + - Repository: + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package big_update@1.0.0` + + - with_updates@1.0.0 + - Repository: + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package with_updates@1.0.0` + + - without_updates@1.0.0 + - Repository: + - Detailed warning command: `cargo report future-incompatibilities --id 1 --package without_updates@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 +information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section + +The package `big_update v1.0.0` currently triggers the following future incompatibility lints: +> [WARNING] unused variable: `x` +... + +The package `with_updates v1.0.0` currently triggers the following future incompatibility lints: +> [WARNING] unused variable: `x` ... + +The package `without_updates v1.0.0` currently triggers the following future incompatibility lints: +> [WARNING] unused variable: `x` +... + "#]]) .run(); } From 0b2299e889c2dca56b16d0548e1a76cafb7f6a14 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 21 Mar 2025 16:28:57 -0700 Subject: [PATCH 7/7] Remove an excess newline The udpate_message already has a newline when it is there. When it is an empty string, it ends up adding an unnecessary blank line. --- src/cargo/core/compiler/future_incompat.rs | 2 +- tests/testsuite/future_incompat_report.rs | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/future_incompat.rs b/src/cargo/core/compiler/future_incompat.rs index fe9967e3ac6..8cc3878fc13 100644 --- a/src/cargo/core/compiler/future_incompat.rs +++ b/src/cargo/core/compiler/future_incompat.rs @@ -483,7 +483,7 @@ You may want to consider updating them to a newer version to see if the issue ha " To solve this problem, you can try the following approaches: -{update_message} +{update_message}\ - If the issue is not solved by updating the dependencies, a fix has to be implemented by those dependencies. You can help with that by notifying the maintainers of this problem (e.g. by creating a bug report) or by proposing a diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index b1e5f060c3d..6e6f8c7ca53 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -149,7 +149,6 @@ fn incompat_in_dependency() { [NOTE] To solve this problem, you can try the following approaches: - - If the issue is not solved by updating the dependencies, a fix has to be implemented by those dependencies. You can help with that by notifying the maintainers of this problem (e.g. by creating a bug report) or by proposing a @@ -184,7 +183,6 @@ means and how to resolve it. To solve this problem, you can try the following approaches: - - If the issue is not solved by updating the dependencies, a fix has to be implemented by those dependencies. You can help with that by notifying the maintainers of this problem (e.g. by creating a bug report) or by proposing a @@ -634,7 +632,6 @@ fix to the maintainers (e.g. by creating a pull request): section in `Cargo.toml` to use your own version of the dependency. For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]].unordered()) @@ -662,7 +659,6 @@ You may want to consider updating them to a newer version to see if the issue ha big_update v1.0.0 has the following newer versions available: 2.0.0 with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 - - If the issue is not solved by updating the dependencies, a fix has to be implemented by those dependencies. You can help with that by notifying the maintainers of this problem (e.g. by creating a bug report) or by proposing a @@ -724,7 +720,6 @@ fn correct_report_id_when_cached() { [NOTE] To solve this problem, you can try the following approaches: - - If the issue is not solved by updating the dependencies, a fix has to be implemented by those dependencies. You can help with that by notifying the maintainers of this problem (e.g. by creating a bug report) or by proposing a @@ -752,7 +747,6 @@ https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch [NOTE] To solve this problem, you can try the following approaches: - - If the issue is not solved by updating the dependencies, a fix has to be implemented by those dependencies. You can help with that by notifying the maintainers of this problem (e.g. by creating a bug report) or by proposing a